appflare 0.2.27 → 0.2.28

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.
@@ -130,24 +130,14 @@ export function createStorageClient(
130
130
 
131
131
  return (await response.json()) as StorageSignedUrlResponse;
132
132
  },
133
- preview: async (args) => {
133
+ preview: (args) => {
134
134
  const query = new URLSearchParams({
135
135
  path: args.path,
136
136
  ...(typeof args.expiresIn === "number"
137
137
  ? { expiresIn: String(args.expiresIn) }
138
138
  : {}),
139
139
  });
140
- const response = await request(
141
- \`\${endpoint}/storage/preview?\${query.toString()}\`,
142
- {
143
- headers: await createAuthorizedHeaders(undefined, onGetAuthToken),
144
- },
145
- );
146
- if (!response.ok) {
147
- throw new Error(await response.text());
148
- }
149
-
150
- return (await response.json()) as StorageSignedUrlResponse;
140
+ return \`\${endpoint}/storage/download?\${query.toString()}\`;
151
141
  },
152
142
  delete: async (args) => {
153
143
  const query = new URLSearchParams({
@@ -159,7 +159,7 @@ export type StorageClient = {
159
159
  preview: (args: {
160
160
  path: string;
161
161
  expiresIn?: number;
162
- }) => Promise<StorageSignedUrlResponse>;
162
+ }) => string;
163
163
  delete: (args: { path: string }) => Promise<{ ok: boolean; path: string }>;
164
164
  list: (args?: {
165
165
  prefix?: string;
@@ -83,21 +83,28 @@ export function registerGeneratedStorageRoutes(
83
83
  try {
84
84
  const path = readStoragePath(c);
85
85
  const fileName = c.req.query("fileName") ?? undefined;
86
- const expiresIn = parseExpiresIn(c.req.query("expiresIn"));
87
86
 
88
- // For now, we'll return an error since signed URLs are not available
89
- // In the future, we could implement direct file serving here
90
- return c.json(
91
- { message: "Download via signed URL is not available in this runtime. Use direct file access instead." },
92
- 501,
93
- );
87
+ const file = await ctx.storage.get({ path });
88
+ if (!file) {
89
+ return c.json({ message: "File not found" }, 404);
90
+ }
91
+
92
+ const headers: Record<string, string> = {};
93
+ if (file.contentType) {
94
+ headers["content-type"] = file.contentType;
95
+ }
96
+ if (fileName) {
97
+ headers["content-disposition"] = \`attachment; filename="\${fileName}"\`;
98
+ }
99
+
100
+ return c.body(file.body, 200, headers);
94
101
  } catch (error) {
95
102
  if (error instanceof AppflareHandledError) {
96
103
  return c.json(error.payload, error.status as any);
97
104
  }
98
105
 
99
106
  return c.json(
100
- { message: (error as Error).message ?? "Unable to create download URL" },
107
+ { message: (error as Error).message ?? "Unable to download file" },
101
108
  400,
102
109
  );
103
110
  }
package/dist/cli/index.js CHANGED
@@ -872,24 +872,14 @@ export function createStorageClient(
872
872
 
873
873
  return (await response.json()) as StorageSignedUrlResponse;
874
874
  },
875
- preview: async (args) => {
875
+ preview: (args) => {
876
876
  const query = new URLSearchParams({
877
877
  path: args.path,
878
878
  ...(typeof args.expiresIn === "number"
879
879
  ? { expiresIn: String(args.expiresIn) }
880
880
  : {}),
881
881
  });
882
- const response = await request(
883
- \`\${endpoint}/storage/preview?\${query.toString()}\`,
884
- {
885
- headers: await createAuthorizedHeaders(undefined, onGetAuthToken),
886
- },
887
- );
888
- if (!response.ok) {
889
- throw new Error(await response.text());
890
- }
891
-
892
- return (await response.json()) as StorageSignedUrlResponse;
882
+ return \`\${endpoint}/storage/download?\${query.toString()}\`;
893
883
  },
894
884
  delete: async (args) => {
895
885
  const query = new URLSearchParams({
@@ -1103,7 +1093,7 @@ export type StorageClient = {
1103
1093
  preview: (args: {
1104
1094
  path: string;
1105
1095
  expiresIn?: number;
1106
- }) => Promise<StorageSignedUrlResponse>;
1096
+ }) => string;
1107
1097
  delete: (args: { path: string }) => Promise<{ ok: boolean; path: string }>;
1108
1098
  list: (args?: {
1109
1099
  prefix?: string;
@@ -5678,21 +5668,28 @@ export function registerGeneratedStorageRoutes(
5678
5668
  try {
5679
5669
  const path = readStoragePath(c);
5680
5670
  const fileName = c.req.query("fileName") ?? undefined;
5681
- const expiresIn = parseExpiresIn(c.req.query("expiresIn"));
5682
5671
 
5683
- // For now, we'll return an error since signed URLs are not available
5684
- // In the future, we could implement direct file serving here
5685
- return c.json(
5686
- { message: "Download via signed URL is not available in this runtime. Use direct file access instead." },
5687
- 501,
5688
- );
5672
+ const file = await ctx.storage.get({ path });
5673
+ if (!file) {
5674
+ return c.json({ message: "File not found" }, 404);
5675
+ }
5676
+
5677
+ const headers: Record<string, string> = {};
5678
+ if (file.contentType) {
5679
+ headers["content-type"] = file.contentType;
5680
+ }
5681
+ if (fileName) {
5682
+ headers["content-disposition"] = \`attachment; filename="\${fileName}"\`;
5683
+ }
5684
+
5685
+ return c.body(file.body, 200, headers);
5689
5686
  } catch (error) {
5690
5687
  if (error instanceof AppflareHandledError) {
5691
5688
  return c.json(error.payload, error.status as any);
5692
5689
  }
5693
5690
 
5694
5691
  return c.json(
5695
- { message: (error as Error).message ?? "Unable to create download URL" },
5692
+ { message: (error as Error).message ?? "Unable to download file" },
5696
5693
  400,
5697
5694
  );
5698
5695
  }
@@ -872,24 +872,14 @@ export function createStorageClient(
872
872
 
873
873
  return (await response.json()) as StorageSignedUrlResponse;
874
874
  },
875
- preview: async (args) => {
875
+ preview: (args) => {
876
876
  const query = new URLSearchParams({
877
877
  path: args.path,
878
878
  ...(typeof args.expiresIn === "number"
879
879
  ? { expiresIn: String(args.expiresIn) }
880
880
  : {}),
881
881
  });
882
- const response = await request(
883
- \`\${endpoint}/storage/preview?\${query.toString()}\`,
884
- {
885
- headers: await createAuthorizedHeaders(undefined, onGetAuthToken),
886
- },
887
- );
888
- if (!response.ok) {
889
- throw new Error(await response.text());
890
- }
891
-
892
- return (await response.json()) as StorageSignedUrlResponse;
882
+ return \`\${endpoint}/storage/download?\${query.toString()}\`;
893
883
  },
894
884
  delete: async (args) => {
895
885
  const query = new URLSearchParams({
@@ -1103,7 +1093,7 @@ export type StorageClient = {
1103
1093
  preview: (args: {
1104
1094
  path: string;
1105
1095
  expiresIn?: number;
1106
- }) => Promise<StorageSignedUrlResponse>;
1096
+ }) => string;
1107
1097
  delete: (args: { path: string }) => Promise<{ ok: boolean; path: string }>;
1108
1098
  list: (args?: {
1109
1099
  prefix?: string;
@@ -5678,21 +5668,28 @@ export function registerGeneratedStorageRoutes(
5678
5668
  try {
5679
5669
  const path = readStoragePath(c);
5680
5670
  const fileName = c.req.query("fileName") ?? undefined;
5681
- const expiresIn = parseExpiresIn(c.req.query("expiresIn"));
5682
5671
 
5683
- // For now, we'll return an error since signed URLs are not available
5684
- // In the future, we could implement direct file serving here
5685
- return c.json(
5686
- { message: "Download via signed URL is not available in this runtime. Use direct file access instead." },
5687
- 501,
5688
- );
5672
+ const file = await ctx.storage.get({ path });
5673
+ if (!file) {
5674
+ return c.json({ message: "File not found" }, 404);
5675
+ }
5676
+
5677
+ const headers: Record<string, string> = {};
5678
+ if (file.contentType) {
5679
+ headers["content-type"] = file.contentType;
5680
+ }
5681
+ if (fileName) {
5682
+ headers["content-disposition"] = \`attachment; filename="\${fileName}"\`;
5683
+ }
5684
+
5685
+ return c.body(file.body, 200, headers);
5689
5686
  } catch (error) {
5690
5687
  if (error instanceof AppflareHandledError) {
5691
5688
  return c.json(error.payload, error.status as any);
5692
5689
  }
5693
5690
 
5694
5691
  return c.json(
5695
- { message: (error as Error).message ?? "Unable to create download URL" },
5692
+ { message: (error as Error).message ?? "Unable to download file" },
5696
5693
  400,
5697
5694
  );
5698
5695
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "appflare",
3
- "version": "0.2.27",
3
+ "version": "0.2.28",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",