UNPKG

@sync-in/server

Version:

The secure, open-source platform for file storage, sharing, collaboration, and sync

293 lines (292 loc) 14.3 kB
/* * Copyright (C) 2012-2025 Johan Legrand <johan.legrand@sync-in.com> * This file is part of Sync-in | The open source file sync and share solution * See the LICENSE file for licensing details */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "SharesController", { enumerable: true, get: function() { return SharesController; } }); const _common = require("@nestjs/common"); const _contextinterceptor = require("../../infrastructure/context/interceptors/context.interceptor"); const _links = require("../links/constants/links"); const _createorupdatelinkdto = require("../links/dto/create-or-update-link.dto"); const _user = require("../users/constants/user"); const _permissionsdecorator = require("../users/decorators/permissions.decorator"); const _rolesdecorator = require("../users/decorators/roles.decorator"); const _userdecorator = require("../users/decorators/user.decorator"); const _permissionsguard = require("../users/guards/permissions.guard"); const _rolesguard = require("../users/guards/roles.guard"); const _usermodel = require("../users/models/user.model"); const _routes = require("./constants/routes"); const _createorupdatesharedto = require("./dto/create-or-update-share.dto"); const _sharesmanagerservice = require("./services/shares-manager.service"); function _ts_decorate(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; } function _ts_metadata(k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); } function _ts_param(paramIndex, decorator) { return function(target, key) { decorator(target, key, paramIndex); }; } let SharesController = class SharesController { /* MANAGE COMMON SHARES */ listShares(user) { return this.sharesManager.listShares(user); } getShareWithMembers(user, shareId) { return this.sharesManager.getShareWithMembers(user, shareId); } createShare(user, createOrUpdateShareDto) { if (createOrUpdateShareDto.parent?.alias) { return this.sharesManager.createChildShare(user, createOrUpdateShareDto); } return this.sharesManager.createShare(user, createOrUpdateShareDto); } updateShare(user, shareId, createOrUpdateShareDto) { return this.sharesManager.updateShare(user, shareId, createOrUpdateShareDto); } deleteShare(user, shareId) { return this.sharesManager.deleteShare(user, shareId); } /* MANAGE CHILD SHARES */ listChildShares(user, shareId) { return this.sharesManager.listChildShares(user, shareId); } getShareChild(user, shareId, childId) { return this.sharesManager.getChildShare(user, shareId, childId); } updateShareChild(user, shareId, childId, createOrUpdateShareDto) { return this.sharesManager.updateChildShare(user, shareId, childId, createOrUpdateShareDto); } deleteShareChild(user, shareId, childId) { return this.sharesManager.deleteChildShare(user, shareId, childId); } /* MANAGE LINK SHARES */ generateUUID(user) { return this.sharesManager.generateLinkUUID(user.id); } listShareLinks(user) { return this.sharesManager.listShareLinks(user); } getShareLink(user, shareId) { return this.sharesManager.getShareLink(user, shareId); } getChildShareLink(user, shareId, childId) { return this.sharesManager.getChildShare(user, shareId, childId, true); } getLinkFromSpaceOrShare(user, linkId, type, typeId) { return this.sharesManager.getLinkFromSpaceOrShare(user, linkId, typeId, type); } updateLinkFromSpaceOrShare(user, linkId, type, typeId, createOrUpdateLinkDto) { return this.sharesManager.updateLinkFromSpaceOrShare(user, linkId, typeId, type, createOrUpdateLinkDto, true); } constructor(sharesManager){ this.sharesManager = sharesManager; } }; _ts_decorate([ (0, _common.Get)(_routes.SHARES_ROUTE.LIST), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SharesController.prototype, "listShares", null); _ts_decorate([ (0, _common.Get)(':id'), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Param)('id', _common.ParseIntPipe)), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, Number ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SharesController.prototype, "getShareWithMembers", null); _ts_decorate([ (0, _common.Post)(), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Body)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, typeof _createorupdatesharedto.CreateOrUpdateShareDto === "undefined" ? Object : _createorupdatesharedto.CreateOrUpdateShareDto ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SharesController.prototype, "createShare", null); _ts_decorate([ (0, _common.Put)(':id'), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Param)('id', _common.ParseIntPipe)), _ts_param(2, (0, _common.Body)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, Number, typeof _createorupdatesharedto.CreateOrUpdateShareDto === "undefined" ? Object : _createorupdatesharedto.CreateOrUpdateShareDto ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SharesController.prototype, "updateShare", null); _ts_decorate([ (0, _common.Delete)(':id'), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Param)('id', _common.ParseIntPipe)), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, Number ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SharesController.prototype, "deleteShare", null); _ts_decorate([ (0, _common.Get)(`:id/${_routes.SHARES_ROUTE.CHILDREN}`), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Param)('id', _common.ParseIntPipe)), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, Number ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SharesController.prototype, "listChildShares", null); _ts_decorate([ (0, _common.Get)(`:id/${_routes.SHARES_ROUTE.CHILDREN}/:cid`), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Param)('id', _common.ParseIntPipe)), _ts_param(2, (0, _common.Param)('cid', _common.ParseIntPipe)), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, Number, Number ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SharesController.prototype, "getShareChild", null); _ts_decorate([ (0, _common.Put)(`:id/${_routes.SHARES_ROUTE.CHILDREN}/:cid`), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Param)('id', _common.ParseIntPipe)), _ts_param(2, (0, _common.Param)('cid', _common.ParseIntPipe)), _ts_param(3, (0, _common.Body)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, Number, Number, typeof _createorupdatesharedto.CreateOrUpdateShareDto === "undefined" ? Object : _createorupdatesharedto.CreateOrUpdateShareDto ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SharesController.prototype, "updateShareChild", null); _ts_decorate([ (0, _common.Delete)(`:id/${_routes.SHARES_ROUTE.CHILDREN}/:cid`), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Param)('id', _common.ParseIntPipe)), _ts_param(2, (0, _common.Param)('cid', _common.ParseIntPipe)), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, Number, Number ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SharesController.prototype, "deleteShareChild", null); _ts_decorate([ (0, _common.Get)(_routes.SHARES_ROUTE.LINKS_UUID), (0, _permissionsdecorator.UserHavePermission)([ _user.USER_PERMISSION.SHARES_ADMIN, _user.USER_PERMISSION.SPACES_ADMIN ]), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SharesController.prototype, "generateUUID", null); _ts_decorate([ (0, _common.Get)(_routes.SHARES_ROUTE.LINKS_LIST), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SharesController.prototype, "listShareLinks", null); _ts_decorate([ (0, _common.Get)(`${_routes.SHARES_ROUTE.LINKS}/:id`), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Param)('id', _common.ParseIntPipe)), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, Number ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SharesController.prototype, "getShareLink", null); _ts_decorate([ (0, _common.Get)(`${_routes.SHARES_ROUTE.LINKS}/:id/${_routes.SHARES_ROUTE.CHILDREN}/:cid`), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Param)('id', _common.ParseIntPipe)), _ts_param(2, (0, _common.Param)('cid', _common.ParseIntPipe)), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, Number, Number ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SharesController.prototype, "getChildShareLink", null); _ts_decorate([ (0, _common.Get)(`${_routes.SHARES_ROUTE.LINKS}/:id/:type(space|share)/:typeId`), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Param)('id', _common.ParseIntPipe)), _ts_param(2, (0, _common.Param)('type')), _ts_param(3, (0, _common.Param)('typeId', _common.ParseIntPipe)), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, Number, typeof _links.LINK_TYPE === "undefined" ? Object : _links.LINK_TYPE, Number ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SharesController.prototype, "getLinkFromSpaceOrShare", null); _ts_decorate([ (0, _common.Put)(`${_routes.SHARES_ROUTE.LINKS}/:id/:type(space|share)/:typeId`), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Param)('id', _common.ParseIntPipe)), _ts_param(2, (0, _common.Param)('type')), _ts_param(3, (0, _common.Param)('typeId', _common.ParseIntPipe)), _ts_param(4, (0, _common.Body)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, Number, typeof _links.LINK_TYPE === "undefined" ? Object : _links.LINK_TYPE, Number, typeof _createorupdatelinkdto.CreateOrUpdateLinkDto === "undefined" ? Object : _createorupdatelinkdto.CreateOrUpdateLinkDto ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SharesController.prototype, "updateLinkFromSpaceOrShare", null); SharesController = _ts_decorate([ (0, _common.Controller)(_routes.SHARES_ROUTE.BASE), (0, _rolesdecorator.UserHaveRole)(_user.USER_ROLE.USER), (0, _permissionsdecorator.UserHavePermission)(_user.USER_PERMISSION.SHARES_ADMIN), (0, _common.UseGuards)(_rolesguard.UserRolesGuard, _permissionsguard.UserPermissionsGuard), (0, _common.UseInterceptors)(_contextinterceptor.ContextInterceptor), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _sharesmanagerservice.SharesManager === "undefined" ? Object : _sharesmanagerservice.SharesManager ]) ], SharesController); //# sourceMappingURL=shares.controller.js.map