fix: hash tag cannot be used as part of url
This commit is contained in:
parent
dd80764a99
commit
82228da8fa
3 changed files with 13 additions and 13 deletions
|
|
@ -22,7 +22,7 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import { StorageFile } from "../interfaces/storage-fs";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
|
||||
import { copyCond, pathExist } from "../utils/minio";
|
||||
import { copyCond, pathExist, replaceIllegalChars } from "../utils/minio";
|
||||
|
||||
const DEFAULT_BUCKET = process.env.MINIO_BUCKET;
|
||||
const DEFAULT_INDEX = process.env.ELASTICSEARCH_INDEX;
|
||||
|
|
@ -149,7 +149,7 @@ export class FileController extends Controller {
|
|||
}
|
||||
|
||||
const basePath = `${cabinetName}/${drawerName}/${folderName}/`;
|
||||
const pathname = `${basePath}${body.file}`;
|
||||
const pathname = `${basePath}${replaceIllegalChars(body.file)}`;
|
||||
|
||||
if (!(await pathExist(DEFAULT_BUCKET!, basePath))) {
|
||||
throw new HttpError(
|
||||
|
|
@ -180,7 +180,7 @@ export class FileController extends Controller {
|
|||
const metadata: Partial<StorageFile> = {
|
||||
pathname,
|
||||
path: basePath,
|
||||
fileName: body.file,
|
||||
fileName: replaceIllegalChars( body.file ),
|
||||
fileSize: 0,
|
||||
fileType: "",
|
||||
title: body.title ?? "",
|
||||
|
|
@ -272,7 +272,7 @@ export class FileController extends Controller {
|
|||
|
||||
// assume user will probably replace file by re-upload but maybe just rename
|
||||
if (body.file) {
|
||||
const destination = `${basePath}${body.file}`;
|
||||
const destination = `${basePath}${replaceIllegalChars(body.file)}`;
|
||||
const source = `/${DEFAULT_BUCKET}/${basePath}${fileName}`;
|
||||
const copy = await minioClient.copyObject(DEFAULT_BUCKET!, destination, source, copyCond);
|
||||
|
||||
|
|
@ -293,7 +293,7 @@ export class FileController extends Controller {
|
|||
doc: {
|
||||
pathname: destination,
|
||||
path: basePath,
|
||||
fileName: body.file,
|
||||
fileName: replaceIllegalChars(body.file),
|
||||
updatedAt: new Date().toISOString(),
|
||||
updatedBy: request.user.preferred_username ?? "n/a",
|
||||
},
|
||||
|
|
@ -331,7 +331,7 @@ export class FileController extends Controller {
|
|||
? {
|
||||
upload: await minioClient.presignedPutObject(
|
||||
DEFAULT_BUCKET!,
|
||||
`${basePath}${body.file ?? fileName}`,
|
||||
`${basePath}${replaceIllegalChars(body.file) ?? fileName}`,
|
||||
),
|
||||
}
|
||||
: this.setStatus(HttpStatusCode.NO_CONTENT);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import { StorageFile } from "../interfaces/storage-fs";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
|
||||
import { copyCond, pathExist } from "../utils/minio";
|
||||
import { copyCond, pathExist, replaceIllegalChars } from "../utils/minio";
|
||||
|
||||
const DEFAULT_BUCKET = process.env.MINIO_BUCKET;
|
||||
const DEFAULT_INDEX = process.env.ELASTICSEARCH_INDEX;
|
||||
|
|
@ -155,7 +155,7 @@ export class SubFolderFileController extends Controller {
|
|||
}
|
||||
|
||||
const basePath = `${cabinetName}/${drawerName}/${folderName}/${subFolderName}/`;
|
||||
const pathname = `${basePath}${body.file}`;
|
||||
const pathname = `${basePath}${replaceIllegalChars(body.file)}`;
|
||||
|
||||
if (!(await pathExist(DEFAULT_BUCKET!, basePath))) {
|
||||
throw new HttpError(
|
||||
|
|
@ -186,7 +186,7 @@ export class SubFolderFileController extends Controller {
|
|||
const metadata: Partial<StorageFile> = {
|
||||
pathname,
|
||||
path: basePath,
|
||||
fileName: body.file,
|
||||
fileName: replaceIllegalChars(body.file),
|
||||
fileSize: 0,
|
||||
fileType: "",
|
||||
title: body.title ?? "",
|
||||
|
|
@ -279,7 +279,7 @@ export class SubFolderFileController extends Controller {
|
|||
|
||||
// assume user will probably replace file by re-upload but maybe just rename
|
||||
if (body.file) {
|
||||
const destination = `${basePath}${body.file}`;
|
||||
const destination = `${basePath}${replaceIllegalChars(body.file)}`;
|
||||
const source = `/${DEFAULT_BUCKET}/${basePath}${fileName}`;
|
||||
const copy = await minioClient.copyObject(DEFAULT_BUCKET!, destination, source, copyCond);
|
||||
|
||||
|
|
@ -299,7 +299,7 @@ export class SubFolderFileController extends Controller {
|
|||
id,
|
||||
doc: {
|
||||
pathname: destination,
|
||||
fileName: body.file,
|
||||
fileName: replaceIllegalChars(body.file),
|
||||
updatedAt: new Date().toISOString(),
|
||||
updatedBy: request.user.preferred_username ?? "n/a",
|
||||
},
|
||||
|
|
@ -337,7 +337,7 @@ export class SubFolderFileController extends Controller {
|
|||
? {
|
||||
upload: await minioClient.presignedPutObject(
|
||||
DEFAULT_BUCKET!,
|
||||
`${basePath}${body.file ?? fileName}`,
|
||||
`${basePath}${replaceIllegalChars(body.file) ?? fileName}`,
|
||||
),
|
||||
}
|
||||
: this.setStatus(HttpStatusCode.NO_CONTENT);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import minioClient from "../minio";
|
|||
* @returns illegal character replaced path
|
||||
*/
|
||||
export function replaceIllegalChars(path: string, replace = "-") {
|
||||
return path.replace(/[/\\?%*:|"<>]/g, replace);
|
||||
return path.replace(/[/\\?%*:|"<>#]/g, replace);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue