picgo-plugin-gitee-smart
Version:
picgo uploader for gitee with autofillextname if extname of img is missing
75 lines (74 loc) • 2.42 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPath = exports.pathJoin = exports.unzip = exports.zip = exports.getNow = void 0;
const dayjs_1 = __importDefault(require("dayjs"));
const normalize_path_1 = __importDefault(require("normalize-path"));
const path_1 = require("path");
function getNow() {
return dayjs_1.default().format('YYYY-MM-DD hh:mm:ss');
}
exports.getNow = getNow;
function zip(img) {
return {
f: img.fileName,
s: img.sha
};
}
exports.zip = zip;
function unzip(img) {
const { f: fileName, s } = img;
const extname = fileName.split('.').slice(-1)[0];
return {
fileName,
id: s,
sha: s,
extname,
imgUrl: '',
type: ''
};
}
exports.unzip = unzip;
function pathJoin(...arg) {
return normalize_path_1.default(path_1.join.apply(null, arg));
}
exports.pathJoin = pathJoin;
function getPath(path, customPath) {
if (customPath === '') {
return path;
}
else {
let date = new Date();
let year = date.getFullYear();
let month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1);
let day = date.getDay() < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1);
if (customPath === 'year') {
return path.replace('$customPath', year + '');
}
else if (customPath === 'yearQuarter') {
let quarter = 'spring';
if (month >= 4 && month <= 6) {
quarter = 'summer';
}
else if (month >= 7 && month <= 9) {
quarter = 'autumn';
}
else if (month >= 10 && month <= 12) {
quarter = 'winter';
}
return path.replace('$customPath', year + '-' + quarter);
}
else if (customPath === 'yearMonth') {
return path.replace('$customPath', year + '-' + month);
}
else if (customPath === 'yearMonthDay') {
return path.replace('$customPath', dayjs_1.default().format('YYYY-MM-DD'));
}
else {
return path;
}
}
}
exports.getPath = getPath;