Add file download link in files page
This commit is contained in:
1 parent
e9a4676f5c
commit
540898de21
3 files changed
+38
No files matched your search
@@ -457,6 +457,36 @@ for (const [resource, flags] of Object.entries(resources)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
router.get("/blob/files/:id", async (ctx) => {
|
||||||
|
const authorizer: Authorizer = ctx.state.authorizer;
|
||||||
|
const resource = "files";
|
||||||
|
const id = ctx.params.id;
|
||||||
|
|
||||||
|
const log = {
|
||||||
|
message: `Download ${resource}`,
|
||||||
|
context: ctx,
|
||||||
|
id: id,
|
||||||
|
};
|
||||||
|
|
||||||
|
const filter = and(authorizer.getFilter(resource, 2), [
|
||||||
|
"=",
|
||||||
|
["PARAM", RESOURCE_IDS[resource]],
|
||||||
|
ctx.params.id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!authorizer.hasAccess(resource, 2)) {
|
||||||
|
logUnauthorizedWarning(log);
|
||||||
|
return void (ctx.status = 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
const count = await db.count(resource, filter);
|
||||||
|
if (!count) return void (ctx.status = 404);
|
||||||
|
|
||||||
|
logger.accessInfo(log);
|
||||||
|
ctx.body = db.downloadFile(id);
|
||||||
|
ctx.attachment(id);
|
||||||
|
});
|
||||||
|
|
||||||
router.put("/files/:id", async (ctx) => {
|
router.put("/files/:id", async (ctx) => {
|
||||||
const authorizer: Authorizer = ctx.state.authorizer;
|
const authorizer: Authorizer = ctx.state.authorizer;
|
||||||
const resource = "files";
|
const resource = "files";
|
||||||
|
|||||||
@@ -315,6 +315,11 @@ export function deleteUser(id: string): Promise<void> {
|
|||||||
return deleteResource("users", id);
|
return deleteResource("users", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function downloadFile(filename: string): Readable {
|
||||||
|
const bucket = new GridFSBucket(db);
|
||||||
|
return bucket.openDownloadStreamByName(filename);
|
||||||
|
}
|
||||||
|
|
||||||
export function putFile(
|
export function putFile(
|
||||||
filename: string,
|
filename: string,
|
||||||
metadata: Record<string, string>,
|
metadata: Record<string, string>,
|
||||||
|
|||||||
@@ -212,6 +212,9 @@ export const component: ClosureComponent = (): Component => {
|
|||||||
attrs["sortAttributes"] = sortAttributes;
|
attrs["sortAttributes"] = sortAttributes;
|
||||||
attrs["onSortChange"] = onSortChange;
|
attrs["onSortChange"] = onSortChange;
|
||||||
attrs["downloadUrl"] = downloadUrl;
|
attrs["downloadUrl"] = downloadUrl;
|
||||||
|
attrs["recordActionsCallback"] = (file) => {
|
||||||
|
return [m("a", { href: "api/blob/files/" + file["_id"] }, "Download")];
|
||||||
|
};
|
||||||
|
|
||||||
if (window.authorizer.hasAccess("files", 3)) {
|
if (window.authorizer.hasAccess("files", 3)) {
|
||||||
attrs["actionsCallback"] = (selected: Set<string>): Children => {
|
attrs["actionsCallback"] = (selected: Set<string>): Children => {
|
||||||
|
|||||||
Reference in new issue
Block a user