local_fs_media_storage: make sure containers subfolders exists
to prevent a crash when trying to upload to those containers
This commit is contained in:
parent
7f81810ccb
commit
cda987514c
3 changed files with 13 additions and 3 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -12,7 +12,7 @@ run
|
|||
dumps/bnf
|
||||
dumps/inv
|
||||
dumps/wd
|
||||
storage
|
||||
storage*
|
||||
inventaire-i18n
|
||||
config/.sessions_keys
|
||||
*.ndjson
|
||||
|
|
|
@ -3,14 +3,23 @@
|
|||
// expect the pictures' files to be in ${localStorageFolder}/${container}/
|
||||
|
||||
import parseUrl from 'parseurl'
|
||||
import { uploadContainersNames } from '#controllers/images/lib/containers'
|
||||
import { localStorageFolder } from '#controllers/images/lib/local_client'
|
||||
import { absolutePath } from '#lib/absolute_path'
|
||||
import { bundleError } from '#lib/error/pre_filled'
|
||||
import { mkdirp } from '#lib/fs'
|
||||
import * as regex_ from '#lib/regex'
|
||||
import { logError } from '#lib/utils/logs'
|
||||
|
||||
const imagesAssetsFolder = absolutePath('server', 'assets/images')
|
||||
|
||||
async function createLocalImageStorageSubFolder (container: string) {
|
||||
const folderPath = `${localStorageFolder}/${container}`
|
||||
await mkdirp(folderPath)
|
||||
}
|
||||
|
||||
await Promise.all(uploadContainersNames.map(createLocalImageStorageSubFolder))
|
||||
|
||||
export default {
|
||||
get: (req, res) => {
|
||||
const { pathname } = parseUrl(req)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { stat, unlink, mkdir } from 'node:fs/promises'
|
||||
import { promisify } from 'node:util'
|
||||
import mvWithCallback from 'mv'
|
||||
import type { Path } from '#types/common'
|
||||
|
||||
export const mv = promisify(mvWithCallback)
|
||||
// Using 'unlink' instead of 'rm' until the minimal node version gets above v14.14.0
|
||||
|
@ -8,11 +9,11 @@ export const mv = promisify(mvWithCallback)
|
|||
export const rm = unlink
|
||||
export const getContentLength = src => stat(src).then(({ size }) => size)
|
||||
|
||||
export async function mkdirp (path) {
|
||||
export async function mkdirp (path: Path) {
|
||||
return mkdir(path, { recursive: true })
|
||||
}
|
||||
|
||||
export async function exists (path) {
|
||||
export async function exists (path: Path) {
|
||||
try {
|
||||
await stat(path)
|
||||
return true
|
||||
|
|
Loadingâ¦
Add table
Add a link
Reference in a new issue