fix: Unable to store/read in avatars bucket with local file system storage
closes #5873
This commit is contained in:
@@ -4,13 +4,14 @@ import { Primitive } from "utility-types";
|
||||
import validator from "validator";
|
||||
import isIn from "validator/lib/isIn";
|
||||
import isUUID from "validator/lib/isUUID";
|
||||
import { CollectionPermission } from "@shared/types";
|
||||
import { validateColorHex } from "@shared/utils/color";
|
||||
import { validateIndexCharacters } from "@shared/utils/indexCharacters";
|
||||
import parseMentionUrl from "@shared/utils/parseMentionUrl";
|
||||
import { SLUG_URL_REGEX } from "@shared/utils/urlHelpers";
|
||||
import { isUrl } from "@shared/utils/urls";
|
||||
import { CollectionPermission } from "../shared/types";
|
||||
import { validateColorHex } from "../shared/utils/color";
|
||||
import { validateIndexCharacters } from "../shared/utils/indexCharacters";
|
||||
import { ParamRequiredError, ValidationError } from "./errors";
|
||||
import { Buckets } from "./models/helpers/AttachmentHelper";
|
||||
|
||||
type IncomingValue = Primitive | string[];
|
||||
|
||||
@@ -174,10 +175,15 @@ export const assertCollectionPermission = (
|
||||
|
||||
export class ValidateKey {
|
||||
public static isValid = (key: string) => {
|
||||
const parts = key.split("/").slice(0, -1);
|
||||
let parts = key.split("/");
|
||||
const bucket = parts[0];
|
||||
|
||||
// Avatars do not have a file name at the end of the key
|
||||
parts = bucket === Buckets.avatars ? parts : parts.slice(0, -1);
|
||||
|
||||
return (
|
||||
parts.length === 3 &&
|
||||
isIn(parts[0], ["uploads", "public"]) &&
|
||||
isIn(parts[0], Object.values(Buckets)) &&
|
||||
isUUID(parts[1]) &&
|
||||
isUUID(parts[2])
|
||||
);
|
||||
@@ -192,8 +198,7 @@ export class ValidateKey {
|
||||
.concat(`/${sanitize(filename)}`);
|
||||
};
|
||||
|
||||
public static message =
|
||||
"Must be of the form uploads/<uuid>/<uuid>/<name> or public/<uuid>/<uuid>/<name>";
|
||||
public static message = "Must be of the form <bucket>/<uuid>/<uuid>/<name>";
|
||||
}
|
||||
|
||||
export class ValidateDocumentId {
|
||||
|
||||
Reference in New Issue
Block a user