Skip to content

Commit

Permalink
feat(storage)!: add file upload/update by url instead of base64 (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkopanidis committed Mar 21, 2023
1 parent 956eb32 commit 8b32a8e
Show file tree
Hide file tree
Showing 10 changed files with 369 additions and 323 deletions.
39 changes: 38 additions & 1 deletion modules/storage/src/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ConduitGrpcSdk, {
Query,
RouteOptionType,
RoutingManager,
TYPE,
UnparsedRouterResponse,
} from '@conduitplatform/grpc-sdk';
import { status } from '@grpc/grpc-js';
Expand Down Expand Up @@ -80,6 +81,23 @@ export class AdminRoutes {
new ConduitRouteReturnDefinition('CreateFile', File.name),
this.fileHandlers.createFile.bind(this.fileHandlers),
);
this.routingManager.route(
{
bodyParams: {
name: { type: TYPE.String, required: true },
mimeType: TYPE.String,
folder: { type: TYPE.String, required: false },
size: { type: TYPE.Number, required: false },
container: { type: TYPE.String, required: false },
isPublic: TYPE.Boolean,
},
action: ConduitRouteActions.POST,
path: '/files/upload',
description: `Creates a new file and provides a URL to upload it to.`,
},
new ConduitRouteReturnDefinition('CreateFileByUrl', File.name),
this.fileHandlers.createFileUploadUrl.bind(this.fileHandlers),
);
this.routingManager.route(
{
path: '/files/:id',
Expand All @@ -90,15 +108,34 @@ export class AdminRoutes {
},
bodyParams: {
name: ConduitString.Optional,
data: ConduitString.Optional,
folder: ConduitString.Optional,
container: ConduitString.Optional,
data: ConduitString.Required,
mimeType: ConduitString.Optional,
},
},
new ConduitRouteReturnDefinition('PatchFile', File.name),
this.fileHandlers.updateFile.bind(this.fileHandlers),
);
this.routingManager.route(
{
urlParams: {
id: { type: TYPE.String, required: true },
},
bodyParams: {
name: ConduitString.Optional,
folder: ConduitString.Optional,
container: ConduitString.Optional,
mimeType: ConduitString.Optional,
size: ConduitNumber.Optional,
},
action: ConduitRouteActions.PATCH,
path: '/files/upload/:id',
description: `Updates a file and provides a URL to upload its data to.`,
},
new ConduitRouteReturnDefinition('PatchFileByUrl', 'String'),
this.fileHandlers.updateFileUploadUrl.bind(this.fileHandlers),
);
this.routingManager.route(
{
path: '/files/:id',
Expand Down
4 changes: 4 additions & 0 deletions modules/storage/src/constants/expiry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// 60 minutes
export const SIGNED_URL_EXPIRY = 3600 * 1000;
export const SIGNED_URL_EXPIRY_DATE = () => Date.now() + SIGNED_URL_EXPIRY;
export const SIGNED_URL_EXPIRY_SECONDS = SIGNED_URL_EXPIRY / 1000;
Loading

0 comments on commit 8b32a8e

Please sign in to comment.