更新
This commit is contained in:
1 parent
fe2ad7289f
commit
4804a2031b
7 files changed
+149
-2
No files matched your search
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
// 随机长度字符串
|
||||
const randomString = len => {
|
||||
len = len || 10;
|
||||
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
const maxPos = chars.length;
|
||||
let str = '';
|
||||
for (let i = 0; i < len; i++) {
|
||||
str += chars.charAt(Math.floor(Math.random() * maxPos));
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
const getSuffix = fileName => {
|
||||
const arr = fileName.split('.');
|
||||
let suffix = '';
|
||||
if (arr.length >= 2) {
|
||||
suffix = arr[arr.length - 1];
|
||||
}
|
||||
if (suffix) suffix = `.${suffix}`;
|
||||
return suffix;
|
||||
};
|
||||
|
||||
const getFilePath = type => {
|
||||
const now = new Date();
|
||||
const fullYears = now.getFullYear();
|
||||
const Month = now.getMonth();
|
||||
let typeStr = '';
|
||||
switch (type) {
|
||||
case 'blog':
|
||||
typeStr = 'blog';
|
||||
break;
|
||||
default:
|
||||
typeStr = 'media';
|
||||
break;
|
||||
}
|
||||
const path = `${typeStr}/${fullYears}/${Month}/`;
|
||||
return path;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
randomString,
|
||||
getSuffix,
|
||||
getFilePath,
|
||||
};
|
||||
Reference in new issue
Block a user