Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions apps/api/src/tus/tus-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ export const server = new Server({
}
req.user = response.user;
req.apikey = response.apikey;
req.group = response.group;
} catch (err) {
logger.error({ err }, "Error validating user creds");
throw err;
}
},
onUploadCreate: async (req: any, upload: any) => {
const metadata = upload.metadata;
const { user, apikey } = req;
const { user, apikey, group } = req;

try {
const allowedFileSize = getMaxFileUploadSize(req);
Expand All @@ -69,7 +70,7 @@ export const server = new Server({
mimeType: metadata.mimeType || "application/octet-stream",
accessControl: metadata.access,
caption: metadata.caption,
group: metadata.group || (req.body?.group as string),
group: metadata.group || group,
},
tempFilePath: upload.id,
});
Expand Down Expand Up @@ -117,7 +118,7 @@ server.on(EVENTS.POST_RECEIVE, async (req: any, upload: any) => {

async function getUserAndAPIKey(req: any): Promise<UserWithAPIKey | TusError> {
const signature = req.headers.get("x-medialit-signature");
let user, apikey;
let user, apikey, group;
if (signature) {
const response =
await preSignedUrlService.getUserAndGroupFromPresignedUrl(
Expand All @@ -132,6 +133,7 @@ async function getUserAndAPIKey(req: any): Promise<UserWithAPIKey | TusError> {

user = response.user;
apikey = response.apikey;
group = response.group;
} else {
const apikeyFromHeader = req.headers.get("x-medialit-apikey");
const apikeyFromDB: Apikey | null =
Expand All @@ -152,12 +154,13 @@ async function getUserAndAPIKey(req: any): Promise<UserWithAPIKey | TusError> {
apikey = apikeyFromHeader;
}

return { user, apikey };
return { user, apikey, group };
}

interface UserWithAPIKey {
user: User;
apikey: string;
group?: string;
}

interface TusError {
Expand Down
Loading