Spaces:
Sleeping
Sleeping
Download apps/api/dist/documents/documents.router.js from Benaah/MicProtocol: direct link, hf CLI and curl.
- Browser
- Download file 7.42 kB
-
https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/api/dist/documents/documents.router.js
- Command line
-
hf download hf://spaces/Benaah/MicProtocol/apps/api/dist/documents/documents.router.js
-
curl -L -o documents.router.js https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/api/dist/documents/documents.router.js
7.42 kB
| ; | |
| var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | |
| var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | |
| if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | |
| else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | |
| return c > 3 && r && Object.defineProperty(target, key, r), r; | |
| }; | |
| var __metadata = (this && this.__metadata) || function (k, v) { | |
| if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | |
| }; | |
| var DocumentsRouter_1; | |
| Object.defineProperty(exports, "__esModule", { value: true }); | |
| exports.DocumentsRouter = void 0; | |
| const common_1 = require("@nestjs/common"); | |
| const zod_1 = require("zod"); | |
| const trpc_init_1 = require("../trpc/trpc.init"); | |
| const subscription_features_1 = require("../billing/subscription-features"); | |
| const shared_types_1 = require("@micprotocol/shared-types"); | |
| const documents_service_1 = require("./documents.service"); | |
| let DocumentsRouter = DocumentsRouter_1 = class DocumentsRouter { | |
| documentsService; | |
| logger = new common_1.Logger(DocumentsRouter_1.name); | |
| constructor(documentsService) { | |
| this.documentsService = documentsService; | |
| } | |
| get router() { | |
| return (0, trpc_init_1.router)({ | |
| upload: (0, trpc_init_1.requireFeature)(subscription_features_1.SubscriptionFeature.DOCUMENT_MANAGEMENT) | |
| .input(shared_types_1.uploadDocumentSchema) | |
| .mutation(async ({ ctx, input }) => { | |
| if (!ctx.userId) | |
| throw new Error("Unauthorized"); | |
| if (!ctx.workspaceId) | |
| throw new Error("Workspace context required"); | |
| return this.documentsService.uploadDocument({ | |
| workspaceId: input.workspaceId, | |
| userId: ctx.userId, | |
| title: input.title, | |
| description: input.description, | |
| file: { | |
| buffer: Buffer.from(input.storageKey, "base64"), | |
| originalname: input.storageKey, | |
| mimetype: input.mimeType, | |
| size: input.sizeBytes, | |
| }, | |
| }); | |
| }), | |
| list: trpc_init_1.workspaceProcedure | |
| .input(zod_1.z.object({ | |
| status: zod_1.z.enum(["draft", "active", "revoked", "flagged", "quarantined"]).optional(), | |
| search: zod_1.z.string().optional(), | |
| page: zod_1.z.number().int().min(1).optional(), | |
| limit: zod_1.z.number().int().min(1).max(100).optional(), | |
| }).optional()) | |
| .query(async ({ ctx, input }) => { | |
| if (!ctx.workspaceId) | |
| throw new Error("Workspace context required"); | |
| return this.documentsService.listDocuments(ctx.workspaceId, { | |
| status: input?.status, | |
| search: input?.search, | |
| page: input?.page, | |
| limit: input?.limit, | |
| }); | |
| }), | |
| get: trpc_init_1.workspaceProcedure | |
| .input(zod_1.z.object({ documentId: zod_1.z.string().uuid() })) | |
| .query(async ({ ctx, input }) => { | |
| if (!ctx.workspaceId) | |
| throw new Error("Workspace context required"); | |
| return this.documentsService.getDocument(input.documentId, ctx.workspaceId); | |
| }), | |
| createShare: (0, trpc_init_1.requireFeature)(subscription_features_1.SubscriptionFeature.DOCUMENT_MANAGEMENT) | |
| .input(shared_types_1.createDocumentShareSchema) | |
| .mutation(async ({ ctx, input }) => { | |
| if (!ctx.workspaceId) | |
| throw new Error("Workspace context required"); | |
| return this.documentsService.createShare({ | |
| documentId: input.documentId, | |
| workspaceId: input.workspaceId, | |
| shareType: input.shareType, | |
| accessCode: input.accessCode, | |
| expiresAt: input.expiresAt, | |
| maxDownloads: input.maxDownloads, | |
| }); | |
| }), | |
| revokeShare: (0, trpc_init_1.requireFeature)(subscription_features_1.SubscriptionFeature.DOCUMENT_MANAGEMENT) | |
| .input(shared_types_1.revokeDocumentShareSchema) | |
| .mutation(async ({ ctx, input }) => { | |
| if (!ctx.workspaceId) | |
| throw new Error("Workspace context required"); | |
| return this.documentsService.revokeShare(input.shareId, ctx.workspaceId); | |
| }), | |
| download: trpc_init_1.workspaceProcedure | |
| .input(zod_1.z.object({ | |
| documentId: zod_1.z.string().uuid(), | |
| shareId: zod_1.z.string().uuid().optional(), | |
| })) | |
| .query(async ({ ctx, input }) => { | |
| if (!ctx.workspaceId) | |
| throw new Error("Workspace context required"); | |
| return this.documentsService.getDownloadUrl(input.documentId, ctx.workspaceId, input.shareId ?? null, ctx.userId ?? null, null, null); | |
| }), | |
| verifyIntegrity: (0, trpc_init_1.requireFeature)(subscription_features_1.SubscriptionFeature.DOCUMENT_MANAGEMENT) | |
| .input(shared_types_1.verifyDocumentIntegritySchema) | |
| .query(async ({ ctx, input }) => { | |
| if (!ctx.workspaceId) | |
| throw new Error("Workspace context required"); | |
| return this.documentsService.verifyIntegrity(input.documentId, ctx.workspaceId); | |
| }), | |
| accessLogs: trpc_init_1.workspaceProcedure | |
| .input(zod_1.z.object({ | |
| documentId: zod_1.z.string().uuid(), | |
| page: zod_1.z.number().int().min(1).optional(), | |
| limit: zod_1.z.number().int().min(1).max(100).optional(), | |
| })) | |
| .query(async ({ ctx, input }) => { | |
| if (!ctx.workspaceId) | |
| throw new Error("Workspace context required"); | |
| return this.documentsService.listAccessLogs(input.documentId, ctx.workspaceId, { page: input.page, limit: input.limit }); | |
| }), | |
| delete: (0, trpc_init_1.requireFeature)(subscription_features_1.SubscriptionFeature.DOCUMENT_MANAGEMENT) | |
| .input(zod_1.z.object({ documentId: zod_1.z.string().uuid() })) | |
| .mutation(async ({ ctx, input }) => { | |
| if (!ctx.userId) | |
| throw new Error("Unauthorized"); | |
| if (!ctx.workspaceId) | |
| throw new Error("Workspace context required"); | |
| return this.documentsService.deleteDocument(input.documentId, ctx.workspaceId, ctx.userId); | |
| }), | |
| }); | |
| } | |
| }; | |
| exports.DocumentsRouter = DocumentsRouter; | |
| exports.DocumentsRouter = DocumentsRouter = DocumentsRouter_1 = __decorate([ | |
| (0, common_1.Injectable)(), | |
| __metadata("design:paramtypes", [documents_service_1.DocumentsService]) | |
| ], DocumentsRouter); | |
| //# sourceMappingURL=documents.router.js.map |