mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2026-04-03 19:20:08 +00:00
Compare commits
No commits in common. "c8574dd5b0d1b6949b8010e1fefa445e6f241129" and "e2810c149e64eef8971b23ca2968a4f5dfb2f766" have entirely different histories.
c8574dd5b0
...
e2810c149e
@ -39,7 +39,7 @@ export class CoolPlugin extends BasePluginHook implements BaseUpload {
|
|||||||
async downAndUpload(url: string, fileName?: string) {
|
async downAndUpload(url: string, fileName?: string) {
|
||||||
const { domain } = this.pluginInfo.config;
|
const { domain } = this.pluginInfo.config;
|
||||||
// 从url获取扩展名
|
// 从url获取扩展名
|
||||||
const extend = path.extname(fileName ? fileName : url);
|
const extend = path.extname(url);
|
||||||
const download = require('download');
|
const download = require('download');
|
||||||
// 数据
|
// 数据
|
||||||
const data = url.includes('http')
|
const data = url.includes('http')
|
||||||
@ -69,20 +69,8 @@ export class CoolPlugin extends BasePluginHook implements BaseUpload {
|
|||||||
async uploadWithKey(filePath: any, key: any) {
|
async uploadWithKey(filePath: any, key: any) {
|
||||||
const { domain } = this.pluginInfo.config;
|
const { domain } = this.pluginInfo.config;
|
||||||
const data = fs.readFileSync(filePath);
|
const data = fs.readFileSync(filePath);
|
||||||
// 如果文件夹不存在则创建
|
fs.writeFileSync(path.join(this.app.getBaseDir(), '..', key), data);
|
||||||
const dirPath = path.join(
|
return domain + key;
|
||||||
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