@ruiapp/rapid-core 0.1.76 → 0.1.77

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
@@ -5928,9 +5928,10 @@ var downloadDocumentActionHandler = /*#__PURE__*/Object.freeze({
5928
5928
 
5929
5929
  const code$7 = "downloadFile";
5930
5930
  async function handler$7(plugin, ctx, options) {
5931
- const { server, applicationConfig, routerContext, input } = ctx;
5931
+ const { server, applicationConfig, routerContext } = ctx;
5932
5932
  const { request, response } = routerContext;
5933
5933
  //TODO: only public files can download by this handler
5934
+ const input = ctx.input;
5934
5935
  let fileKey = input.fileKey;
5935
5936
  if (!fileKey && input.fileId) {
5936
5937
  const dataAccessor = ctx.server.getDataAccessor({
@@ -5946,7 +5947,8 @@ async function handler$7(plugin, ctx, options) {
5946
5947
  const filePathName = path__default["default"].join(server.config.localFileStoragePath, fileKey);
5947
5948
  const attachmentFileName = input.fileName || path__default["default"].basename(fileKey);
5948
5949
  response.body = await readFile(filePathName);
5949
- response.headers.set("Content-Disposition", `attachment; filename="${encodeURIComponent(attachmentFileName)}"`);
5950
+ const dispositionType = input.inline ? "inline" : "attachment";
5951
+ response.headers.set("Content-Disposition", `${dispositionType}; filename="${encodeURIComponent(attachmentFileName)}"`);
5950
5952
  }
5951
5953
 
5952
5954
  var downloadFileActionHandler = /*#__PURE__*/Object.freeze({
@@ -1,4 +1,10 @@
1
1
  import { ActionHandlerContext } from "../../../core/actionHandler";
2
2
  import { RapidPlugin } from "../../../core/server";
3
+ export type DownloadFileInput = {
4
+ fileId?: string;
5
+ fileKey?: string;
6
+ fileName?: string;
7
+ inline?: boolean;
8
+ };
3
9
  export declare const code = "downloadFile";
4
10
  export declare function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruiapp/rapid-core",
3
- "version": "0.1.76",
3
+ "version": "0.1.77",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -3,13 +3,22 @@ import { readFile } from "~/utilities/fsUtility";
3
3
  import { ActionHandlerContext } from "~/core/actionHandler";
4
4
  import { RapidPlugin } from "~/core/server";
5
5
 
6
+ export type DownloadFileInput = {
7
+ fileId?: string;
8
+ fileKey?: string;
9
+ fileName?: string;
10
+ inline?: boolean;
11
+ };
12
+
6
13
  export const code = "downloadFile";
7
14
 
8
15
  export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
9
- const { server, applicationConfig, routerContext, input } = ctx;
16
+ const { server, applicationConfig, routerContext } = ctx;
10
17
  const { request, response } = routerContext;
11
18
  //TODO: only public files can download by this handler
12
19
 
20
+ const input: DownloadFileInput = ctx.input;
21
+
13
22
  let fileKey: string = input.fileKey;
14
23
 
15
24
  if (!fileKey && input.fileId) {
@@ -29,5 +38,7 @@ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, op
29
38
  const attachmentFileName = input.fileName || path.basename(fileKey);
30
39
 
31
40
  response.body = await readFile(filePathName);
32
- response.headers.set("Content-Disposition", `attachment; filename="${encodeURIComponent(attachmentFileName)}"`);
41
+
42
+ const dispositionType = input.inline ? "inline" : "attachment";
43
+ response.headers.set("Content-Disposition", `${dispositionType}; filename="${encodeURIComponent(attachmentFileName)}"`);
33
44
  }