Skip to content

Commit 97afd67

Browse files
author
Rajat Saxena
committed
Merge branch 'main' of github.com:codelitdev/medialit into rajat0saxena/issue167
2 parents eea18ab + 8be926c commit 97afd67

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

apps/api/src/tus/tus-server.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ export const server = new Server({
3535
}
3636
req.user = response.user;
3737
req.apikey = response.apikey;
38+
req.group = response.group;
3839
} catch (err) {
3940
logger.error({ err }, "Error validating user creds");
4041
throw err;
4142
}
4243
},
4344
onUploadCreate: async (req: any, upload: any) => {
4445
const metadata = upload.metadata;
45-
const { user, apikey } = req;
46+
const { user, apikey, group } = req;
4647

4748
try {
4849
const allowedFileSize = getMaxFileUploadSize(req);
@@ -69,7 +70,7 @@ export const server = new Server({
6970
mimeType: metadata.mimeType || "application/octet-stream",
7071
accessControl: metadata.access,
7172
caption: metadata.caption,
72-
group: metadata.group || (req.body?.group as string),
73+
group: metadata.group || group,
7374
},
7475
tempFilePath: upload.id,
7576
});
@@ -117,7 +118,7 @@ server.on(EVENTS.POST_RECEIVE, async (req: any, upload: any) => {
117118

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

133134
user = response.user;
134135
apikey = response.apikey;
136+
group = response.group;
135137
} else {
136138
const apikeyFromHeader = req.headers.get("x-medialit-apikey");
137139
const apikeyFromDB: Apikey | null =
@@ -152,12 +154,13 @@ async function getUserAndAPIKey(req: any): Promise<UserWithAPIKey | TusError> {
152154
apikey = apikeyFromHeader;
153155
}
154156

155-
return { user, apikey };
157+
return { user, apikey, group };
156158
}
157159

158160
interface UserWithAPIKey {
159161
user: User;
160162
apikey: string;
163+
group?: string;
161164
}
162165

163166
interface TusError {

0 commit comments

Comments
 (0)