UNPKG

@sync-in/server

Version:

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

408 lines (407 loc) 20.6 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, "SyncController", { enumerable: true, get: function() { return SyncController; } }); const _common = require("@nestjs/common"); const _fastify = require("fastify"); const _authtokenskipdecorator = require("../../authentication/decorators/auth-token-skip.decorator"); const _contextinterceptor = require("../../infrastructure/context/interceptors/context.interceptor"); const _spaceskippermissionsdecorator = require("../spaces/decorators/space-skip-permissions.decorator"); const _spacerequestinterface = require("../spaces/interfaces/space-request.interface"); const _user = require("../users/constants/user"); const _permissionsdecorator = require("../users/decorators/permissions.decorator"); const _userdecorator = require("../users/decorators/user.decorator"); const _permissionsguard = require("../users/guards/permissions.guard"); const _usermodel = require("../users/models/user.model"); const _auth = require("./constants/auth"); const _routes = require("./constants/routes"); const _sync = require("./constants/sync"); const _syncenvironmentdecorator = require("./decorators/sync-environment.decorator"); const _syncclientauthdto = require("./dtos/sync-client-auth.dto"); const _syncoperationsdto = require("./dtos/sync-operations.dto"); const _syncpathdto = require("./dtos/sync-path.dto"); const _syncuploaddto = require("./dtos/sync-upload.dto"); const _syncdiffgzipbodyinterceptor = require("./interceptors/sync-diff-gzip-body.interceptor"); const _syncclientsmanagerservice = require("./services/sync-clients-manager.service"); const _syncmanagerservice = require("./services/sync-manager.service"); const _syncpathsmanagerservice = require("./services/sync-paths-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 SyncController = class SyncController { /* CLIENT */ handshake(req) { if ('user-agent' in req.headers && req.headers['user-agent'].startsWith(_sync.SYNC_IN_SERVER_AGENT)) { return _sync.CHECK_SERVER_RESP; } throw new _common.HttpException('Server not found', _common.HttpStatus.NOT_FOUND); } register(syncClientRegistrationDto, req) { return this.syncClientsManager.register(syncClientRegistrationDto, req.ip); } unregister(user) { return this.syncClientsManager.unregister(user); } checkAppStore() { return this.syncClientsManager.checkAppStore(); } authenticate(type, clientAuthDto, req, res) { return this.syncClientsManager.authenticate(type, clientAuthDto, req.ip, res); } getClients(user) { return this.syncClientsManager.getClients(user); } deleteClient(user, clientId) { return this.syncClientsManager.deleteClient(user, clientId); } /* PATHS */ deleteClientPath(user, clientId, pathId) { return this.syncPathsManager.deletePath(user, pathId, clientId); } updatePath(user, clientId, pathId, syncPathUpdateDto) { return this.syncPathsManager.updatePath(user, clientId, pathId, syncPathUpdateDto); } createPath(req, syncPathDto) { return this.syncPathsManager.createPath(req, syncPathDto); } deletePath(user, pathId) { return this.syncPathsManager.deletePath(user, pathId); } updatePaths(user, syncPathsDto) { return this.syncPathsManager.updatePaths(user, syncPathsDto); } /* OPERATIONS */ diff(user, pathId, syncDiffDto, res) { return this.syncManager.diff(user, pathId, syncDiffDto, res); } download(req, res) { return this.syncManager.download(req, res); } uploadCreate(req, syncUploadDto) { return this.syncManager.upload(req, syncUploadDto); } uploadOverwrite(req, syncUploadDto) { return this.syncManager.upload(req, syncUploadDto); } make(req, syncMakeDto) { return this.syncManager.make(req, syncMakeDto); } props(req, syncPropsDto) { return this.syncManager.props(req, syncPropsDto); } move(req, syncCopyMoveDto) { return this.syncManager.copyMove(req, syncCopyMoveDto, true); } copy(req, syncCopyMoveDto) { return this.syncManager.copyMove(req, syncCopyMoveDto, false); } delete(req) { return this.syncManager.delete(req); } constructor(syncManager, syncClientsManager, syncPathsManager){ this.syncManager = syncManager; this.syncClientsManager = syncClientsManager; this.syncPathsManager = syncPathsManager; } }; _ts_decorate([ (0, _common.Get)(_routes.SYNC_ROUTE.HANDSHAKE), (0, _authtokenskipdecorator.AuthTokenSkip)(), _ts_param(0, (0, _common.Req)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _fastify.FastifyRequest === "undefined" ? Object : _fastify.FastifyRequest ]), _ts_metadata("design:returntype", void 0) ], SyncController.prototype, "handshake", null); _ts_decorate([ (0, _common.Post)(_routes.SYNC_ROUTE.REGISTER), (0, _authtokenskipdecorator.AuthTokenSkip)(), _ts_param(0, (0, _common.Body)()), _ts_param(1, (0, _common.Req)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof SyncClientRegistrationDto === "undefined" ? Object : SyncClientRegistrationDto, typeof _fastify.FastifyRequest === "undefined" ? Object : _fastify.FastifyRequest ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "register", null); _ts_decorate([ (0, _common.Post)(_routes.SYNC_ROUTE.UNREGISTER), (0, _permissionsdecorator.UserHavePermission)(_user.USER_PERMISSION.DESKTOP_APP), (0, _common.UseGuards)(_permissionsguard.UserPermissionsGuard), _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) ], SyncController.prototype, "unregister", null); _ts_decorate([ (0, _common.Get)(_routes.SYNC_ROUTE.APP_STORE), (0, _authtokenskipdecorator.AuthTokenSkip)(), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", []), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "checkAppStore", null); _ts_decorate([ (0, _common.Post)(`${_routes.SYNC_ROUTE.AUTH}/:type`), (0, _authtokenskipdecorator.AuthTokenSkip)(), _ts_param(0, (0, _common.Param)('type')), _ts_param(1, (0, _common.Body)()), _ts_param(2, (0, _common.Req)()), _ts_param(3, (0, _common.Res)({ passthrough: true })), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _auth.CLIENT_AUTH_TYPE === "undefined" ? Object : _auth.CLIENT_AUTH_TYPE, typeof _syncclientauthdto.SyncClientAuthDto === "undefined" ? Object : _syncclientauthdto.SyncClientAuthDto, typeof _fastify.FastifyRequest === "undefined" ? Object : _fastify.FastifyRequest, typeof _fastify.FastifyReply === "undefined" ? Object : _fastify.FastifyReply ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "authenticate", null); _ts_decorate([ (0, _common.Get)(_routes.SYNC_ROUTE.CLIENTS), (0, _permissionsdecorator.UserHavePermission)(_user.USER_PERMISSION.DESKTOP_APP), (0, _common.UseGuards)(_permissionsguard.UserPermissionsGuard), _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) ], SyncController.prototype, "getClients", null); _ts_decorate([ (0, _common.Delete)(`${_routes.SYNC_ROUTE.CLIENTS}/:id`), (0, _permissionsdecorator.UserHavePermission)(_user.USER_PERMISSION.DESKTOP_APP), (0, _common.UseGuards)(_permissionsguard.UserPermissionsGuard), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Param)('id')), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, String ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "deleteClient", null); _ts_decorate([ (0, _common.Delete)(`${_routes.SYNC_ROUTE.CLIENTS}/:id/${_routes.SYNC_ROUTE.PATHS}/:pathId`), (0, _permissionsdecorator.UserHavePermission)(_user.USER_PERMISSION.DESKTOP_APP_SYNC), (0, _common.UseGuards)(_permissionsguard.UserPermissionsGuard), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Param)('id')), _ts_param(2, (0, _common.Param)('pathId', _common.ParseIntPipe)), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, String, Number ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "deleteClientPath", null); _ts_decorate([ (0, _common.Put)(`${_routes.SYNC_ROUTE.CLIENTS}/:id/${_routes.SYNC_ROUTE.PATHS}/:pathId`), (0, _permissionsdecorator.UserHavePermission)(_user.USER_PERMISSION.DESKTOP_APP_SYNC), (0, _common.UseGuards)(_permissionsguard.UserPermissionsGuard), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Param)('id')), _ts_param(2, (0, _common.Param)('pathId', _common.ParseIntPipe)), _ts_param(3, (0, _common.Body)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, String, Number, typeof _syncpathdto.SyncPathUpdateDto === "undefined" ? Object : _syncpathdto.SyncPathUpdateDto ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "updatePath", null); _ts_decorate([ (0, _common.Post)(`${_routes.SYNC_ROUTE.PATHS}/*`), (0, _spaceskippermissionsdecorator.SkipSpacePermissionsCheck)(), (0, _syncenvironmentdecorator.SyncEnvironment)(), _ts_param(0, (0, _common.Req)()), _ts_param(1, (0, _common.Body)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _spacerequestinterface.FastifySpaceRequest === "undefined" ? Object : _spacerequestinterface.FastifySpaceRequest, typeof _syncpathdto.SyncPathDto === "undefined" ? Object : _syncpathdto.SyncPathDto ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "createPath", null); _ts_decorate([ (0, _common.Delete)(`${_routes.SYNC_ROUTE.PATHS}/:id`), (0, _permissionsdecorator.UserHavePermission)(_user.USER_PERMISSION.DESKTOP_APP_SYNC), (0, _common.UseGuards)(_permissionsguard.UserPermissionsGuard), _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) ], SyncController.prototype, "deletePath", null); _ts_decorate([ (0, _common.Put)(_routes.SYNC_ROUTE.PATHS), (0, _permissionsdecorator.UserHavePermission)(_user.USER_PERMISSION.DESKTOP_APP_SYNC), (0, _common.UseGuards)(_permissionsguard.UserPermissionsGuard), (0, _common.UseInterceptors)(_contextinterceptor.ContextInterceptor), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Body)(new _common.ParseArrayPipe({ items: _syncpathdto.SyncPathDto, whitelist: true }))), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, Array ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "updatePaths", null); _ts_decorate([ (0, _common.Post)(`${_routes.SYNC_ROUTE.OPERATION}/${_routes.SYNC_ROUTE.DIFF}/:id`), (0, _permissionsdecorator.UserHavePermission)(_user.USER_PERMISSION.DESKTOP_APP_SYNC), (0, _common.UseGuards)(_permissionsguard.UserPermissionsGuard), (0, _common.UseInterceptors)(_syncdiffgzipbodyinterceptor.SyncDiffGzipBodyInterceptor), _ts_param(0, (0, _userdecorator.GetUser)()), _ts_param(1, (0, _common.Param)('id', _common.ParseIntPipe)), _ts_param(2, (0, _common.Body)()), _ts_param(3, (0, _common.Res)({ passthrough: true })), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _usermodel.UserModel === "undefined" ? Object : _usermodel.UserModel, Number, typeof _syncoperationsdto.SyncDiffDto === "undefined" ? Object : _syncoperationsdto.SyncDiffDto, typeof _fastify.FastifyReply === "undefined" ? Object : _fastify.FastifyReply ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "diff", null); _ts_decorate([ (0, _common.Get)(`${_routes.SYNC_ROUTE.OPERATION}/*`), (0, _syncenvironmentdecorator.SyncEnvironment)(), _ts_param(0, (0, _common.Req)()), _ts_param(1, (0, _common.Res)({ passthrough: true })), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _spacerequestinterface.FastifySpaceRequest === "undefined" ? Object : _spacerequestinterface.FastifySpaceRequest, typeof _fastify.FastifyReply === "undefined" ? Object : _fastify.FastifyReply ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "download", null); _ts_decorate([ (0, _common.Post)(`${_routes.SYNC_ROUTE.OPERATION}/*`), (0, _syncenvironmentdecorator.SyncEnvironment)(), _ts_param(0, (0, _common.Req)()), _ts_param(1, (0, _common.Query)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _spacerequestinterface.FastifySpaceRequest === "undefined" ? Object : _spacerequestinterface.FastifySpaceRequest, typeof _syncuploaddto.SyncUploadDto === "undefined" ? Object : _syncuploaddto.SyncUploadDto ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "uploadCreate", null); _ts_decorate([ (0, _common.Put)(`${_routes.SYNC_ROUTE.OPERATION}/*`), (0, _syncenvironmentdecorator.SyncEnvironment)(), _ts_param(0, (0, _common.Req)()), _ts_param(1, (0, _common.Query)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _spacerequestinterface.FastifySpaceRequest === "undefined" ? Object : _spacerequestinterface.FastifySpaceRequest, typeof _syncuploaddto.SyncUploadDto === "undefined" ? Object : _syncuploaddto.SyncUploadDto ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "uploadOverwrite", null); _ts_decorate([ (0, _common.Post)(`${_routes.SYNC_ROUTE.OPERATION}/${_routes.SYNC_ROUTE.MAKE}/*`), (0, _syncenvironmentdecorator.SyncEnvironment)(), _ts_param(0, (0, _common.Req)()), _ts_param(1, (0, _common.Body)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _spacerequestinterface.FastifySpaceRequest === "undefined" ? Object : _spacerequestinterface.FastifySpaceRequest, typeof _syncoperationsdto.SyncMakeDto === "undefined" ? Object : _syncoperationsdto.SyncMakeDto ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "make", null); _ts_decorate([ (0, _common.Proppatch)(`${_routes.SYNC_ROUTE.OPERATION}/*`), (0, _syncenvironmentdecorator.SyncEnvironment)(), _ts_param(0, (0, _common.Req)()), _ts_param(1, (0, _common.Body)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _spacerequestinterface.FastifySpaceRequest === "undefined" ? Object : _spacerequestinterface.FastifySpaceRequest, typeof _syncoperationsdto.SyncPropsDto === "undefined" ? Object : _syncoperationsdto.SyncPropsDto ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "props", null); _ts_decorate([ (0, _common.Move)(`${_routes.SYNC_ROUTE.OPERATION}/*`), (0, _syncenvironmentdecorator.SyncEnvironment)(), _ts_param(0, (0, _common.Req)()), _ts_param(1, (0, _common.Body)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _spacerequestinterface.FastifySpaceRequest === "undefined" ? Object : _spacerequestinterface.FastifySpaceRequest, typeof _syncoperationsdto.SyncCopyMoveDto === "undefined" ? Object : _syncoperationsdto.SyncCopyMoveDto ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "move", null); _ts_decorate([ (0, _common.Copy)(`${_routes.SYNC_ROUTE.OPERATION}/*`), (0, _syncenvironmentdecorator.SyncEnvironment)(), _ts_param(0, (0, _common.Req)()), _ts_param(1, (0, _common.Body)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _spacerequestinterface.FastifySpaceRequest === "undefined" ? Object : _spacerequestinterface.FastifySpaceRequest, typeof _syncoperationsdto.SyncCopyMoveDto === "undefined" ? Object : _syncoperationsdto.SyncCopyMoveDto ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "copy", null); _ts_decorate([ (0, _common.Delete)(`${_routes.SYNC_ROUTE.OPERATION}/*`), (0, _syncenvironmentdecorator.SyncEnvironment)(), _ts_param(0, (0, _common.Req)()), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _spacerequestinterface.FastifySpaceRequest === "undefined" ? Object : _spacerequestinterface.FastifySpaceRequest ]), _ts_metadata("design:returntype", typeof Promise === "undefined" ? Object : Promise) ], SyncController.prototype, "delete", null); SyncController = _ts_decorate([ (0, _common.Controller)(_routes.SYNC_ROUTE.BASE), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ typeof _syncmanagerservice.SyncManager === "undefined" ? Object : _syncmanagerservice.SyncManager, typeof _syncclientsmanagerservice.SyncClientsManager === "undefined" ? Object : _syncclientsmanagerservice.SyncClientsManager, typeof _syncpathsmanagerservice.SyncPathsManager === "undefined" ? Object : _syncpathsmanagerservice.SyncPathsManager ]) ], SyncController); //# sourceMappingURL=sync.controller.js.map