picgo-plugin-gitee-uploader
Version:
picgo uploader for gitee
70 lines (69 loc) • 2.09 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
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);
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 {
return path;
}
}
}
exports.getPath = getPath;
;