Skip to content

Commit ae6d3b8

Browse files
author
lijunfeng-jk
committed
fix(uploader): fix output filePath of local-uploader
1 parent aaff9cc commit ae6d3b8

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cesarlai/picgo-plugin-filename-format",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"author": "Cesar Lai",
55
"description": "A picgo plugin to format filename by your setting.",
66
"main": "dist/index.js",

src/uploader/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ const createUploader = (): IPlugin => {
1212
const fullConfig = parsePluginSetting(config)
1313
ctx.output = ctx.output.map((img) => {
1414
const imgOutputPath = path.resolve(fullConfig.public, img.fileName)
15-
fs.writeFileSync(imgOutputPath, img.buffer, {
16-
flag: 'r'
17-
})
15+
if (!fs.existsSync(path.dirname(imgOutputPath)))
16+
fs.mkdirSync(path.dirname(imgOutputPath))
1817

19-
const imgUrl = path.resolve('/', img.fileName)
18+
fs.writeFileSync(imgOutputPath, img.buffer)
19+
20+
const imgUrl = [
21+
'/',
22+
img.fileName.replace(/^(?:\\|\/)|(?:\\|\/)$/g, '')
23+
].join('')
2024
img.imgUrl = imgUrl
2125
img.url = imgUrl
26+
2227
return img
2328
})
2429

src/utils/helper.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ const DefaultPluginSetting: Readonly<PluginSetting> = {
1212
export const parsePluginSetting = (
1313
setting: PluginSetting | undefined
1414
): PluginSetting => {
15-
return setting?.format ? setting : DefaultPluginSetting
15+
return {
16+
...DefaultPluginSetting,
17+
...setting
18+
}
1619
}
1720

1821
export const getExt = (fileName: string) => {

0 commit comments

Comments
 (0)