@ruiapp/rapid-core 0.1.72 → 0.1.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -5640,15 +5640,19 @@ const code$7 = "downloadFile";
|
|
|
5640
5640
|
async function handler$7(plugin, ctx, options) {
|
|
5641
5641
|
const { server, applicationConfig, routerContext, input } = ctx;
|
|
5642
5642
|
const { request, response } = routerContext;
|
|
5643
|
-
|
|
5644
|
-
|
|
5645
|
-
|
|
5646
|
-
|
|
5647
|
-
|
|
5648
|
-
|
|
5649
|
-
|
|
5643
|
+
//TODO: only public files can download by this handler
|
|
5644
|
+
let fileKey = input.fileKey;
|
|
5645
|
+
if (!fileKey && input.fileId) {
|
|
5646
|
+
const dataAccessor = ctx.server.getDataAccessor({
|
|
5647
|
+
singularCode: "ecm_storage_object",
|
|
5648
|
+
});
|
|
5649
|
+
const storageObject = await dataAccessor.findById(input.fileId);
|
|
5650
|
+
if (!storageObject) {
|
|
5651
|
+
ctx.output = { error: new Error("Storage object not found.") };
|
|
5652
|
+
return;
|
|
5653
|
+
}
|
|
5654
|
+
fileKey = storageObject.key;
|
|
5650
5655
|
}
|
|
5651
|
-
const fileKey = storageObject.key;
|
|
5652
5656
|
const filePathName = path__default["default"].join(server.config.localFileStoragePath, fileKey);
|
|
5653
5657
|
const attachmentFileName = input.fileName || path__default["default"].basename(fileKey);
|
|
5654
5658
|
response.body = await readFile(filePathName);
|
package/package.json
CHANGED
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { readFile } from "~/utilities/fsUtility";
|
|
3
|
-
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
4
|
-
import { RapidPlugin } from "~/core/server";
|
|
5
|
-
|
|
6
|
-
export const code = "downloadFile";
|
|
7
|
-
|
|
8
|
-
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
|
|
9
|
-
const { server, applicationConfig, routerContext, input } = ctx;
|
|
10
|
-
const { request, response } = routerContext;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { readFile } from "~/utilities/fsUtility";
|
|
3
|
+
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
4
|
+
import { RapidPlugin } from "~/core/server";
|
|
5
|
+
|
|
6
|
+
export const code = "downloadFile";
|
|
7
|
+
|
|
8
|
+
export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
|
|
9
|
+
const { server, applicationConfig, routerContext, input } = ctx;
|
|
10
|
+
const { request, response } = routerContext;
|
|
11
|
+
//TODO: only public files can download by this handler
|
|
12
|
+
|
|
13
|
+
let fileKey: string = input.fileKey;
|
|
14
|
+
|
|
15
|
+
if (!fileKey && input.fileId) {
|
|
16
|
+
const dataAccessor = ctx.server.getDataAccessor({
|
|
17
|
+
singularCode: "ecm_storage_object",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const storageObject = await dataAccessor.findById(input.fileId);
|
|
21
|
+
if (!storageObject) {
|
|
22
|
+
ctx.output = { error: new Error("Storage object not found.") };
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
fileKey = storageObject.key;
|
|
27
|
+
}
|
|
28
|
+
const filePathName = path.join(server.config.localFileStoragePath, fileKey);
|
|
29
|
+
const attachmentFileName = input.fileName || path.basename(fileKey);
|
|
30
|
+
|
|
31
|
+
response.body = await readFile(filePathName);
|
|
32
|
+
response.headers.set("Content-Disposition", `attachment; filename="${encodeURIComponent(attachmentFileName)}"`);
|
|
33
|
+
}
|