mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2025-12-10 16:12:50 +00:00
Compare commits
2 Commits
e2810c149e
...
c8574dd5b0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8574dd5b0 | ||
|
|
f90eb9d63b |
@ -39,7 +39,7 @@ export class CoolPlugin extends BasePluginHook implements BaseUpload {
|
||||
async downAndUpload(url: string, fileName?: string) {
|
||||
const { domain } = this.pluginInfo.config;
|
||||
// 从url获取扩展名
|
||||
const extend = path.extname(url);
|
||||
const extend = path.extname(fileName ? fileName : url);
|
||||
const download = require('download');
|
||||
// 数据
|
||||
const data = url.includes('http')
|
||||
@ -69,8 +69,20 @@ export class CoolPlugin extends BasePluginHook implements BaseUpload {
|
||||
async uploadWithKey(filePath: any, key: any) {
|
||||
const { domain } = this.pluginInfo.config;
|
||||
const data = fs.readFileSync(filePath);
|
||||
fs.writeFileSync(path.join(this.app.getBaseDir(), '..', key), data);
|
||||
return domain + key;
|
||||
// 如果文件夹不存在则创建
|
||||
const dirPath = path.join(
|
||||
pUploadPath(),
|
||||
moment().format('YYYYMMDD'),
|
||||
path.dirname(key)
|
||||
);
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
fs.writeFileSync(
|
||||
path.join(pUploadPath(), moment().format('YYYYMMDD'), key),
|
||||
data
|
||||
);
|
||||
return `${domain}/upload/${moment().format('YYYYMMDD')}/${key}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user