@sync-in/server
Version:
The secure, open-source platform for file storage, sharing, collaboration, and sync
102 lines (101 loc) • 4.95 kB
JavaScript
/*
* 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, "AdminService", {
enumerable: true,
get: function() {
return AdminService;
}
});
const _axios = require("@nestjs/axios");
const _common = require("@nestjs/common");
const _appconstants = require("../../../app.constants");
const _shared = require("../../../common/shared");
const _cacheservice = require("../../../infrastructure/cache/services/cache.service");
const _applicationsconstants = require("../../applications.constants");
const _notifications = require("../../notifications/constants/notifications");
const _notificationsmanagerservice = require("../../notifications/services/notifications-manager.service");
const _adminusersqueriesservice = require("../../users/services/admin-users-queries.service");
const _checkupdate = require("../utils/check-update");
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);
}
let AdminService = class AdminService {
async checkServerUpdateAndNotify() {
let lastVersion;
try {
const res = await this.http.axiosRef({
method: _applicationsconstants.HTTP_METHOD.GET,
url: _shared.APP_URL.SERVER_VERSION_MANIFEST
});
lastVersion = res.data?.tag_name || '';
} catch (e) {
this.logger.warn(`${this.checkServerUpdateAndNotify.name} - unable to check update: ${e}`);
return;
}
if (!lastVersion.startsWith('v')) {
this.logger.warn(`${this.checkServerUpdateAndNotify.name} - unable to check version: ${lastVersion}`);
return;
}
lastVersion = lastVersion.slice(1); // remove 'v' to compare with the current version
if (!(0, _checkupdate.isServerUpdateAvailable)(_appconstants.VERSION, lastVersion)) {
return;
}
// Get the last version that was notified to administrators
const notifiedVersion = await this.cache.get(this.checkServerUpdateAndNotify.name);
if (!notifiedVersion?.version) {
// The version was never stored, do it
await this.cache.set(this.checkServerUpdateAndNotify.name, {
version: _appconstants.VERSION
}, 0);
return;
}
if (notifiedVersion.version === lastVersion) {
// Notification was already sent to administrators
return;
}
const adminsToNotify = await this.adminUsersQueries.listAdminsToNotify();
if (!adminsToNotify.length) {
return;
}
const notification = {
app: _notifications.NOTIFICATION_APP.UPDATE_AVAILABLE,
event: _notifications.NOTIFICATION_APP_EVENT.UPDATE_AVAILABLE,
element: lastVersion,
externalUrl: _shared.APP_URL.RELEASES,
url: null
};
this.notificationsManager.create(adminsToNotify, notification).then(()=>this.cache.set(this.checkServerUpdateAndNotify.name, {
version: lastVersion
}, 0)).catch((e)=>this.logger.error(`${this.checkServerUpdateAndNotify.name} - ${e}`));
}
constructor(http, cache, notificationsManager, adminUsersQueries){
this.http = http;
this.cache = cache;
this.notificationsManager = notificationsManager;
this.adminUsersQueries = adminUsersQueries;
this.logger = new _common.Logger(AdminService.name);
}
};
AdminService = _ts_decorate([
(0, _common.Injectable)(),
_ts_metadata("design:type", Function),
_ts_metadata("design:paramtypes", [
typeof _axios.HttpService === "undefined" ? Object : _axios.HttpService,
typeof _cacheservice.Cache === "undefined" ? Object : _cacheservice.Cache,
typeof _notificationsmanagerservice.NotificationsManager === "undefined" ? Object : _notificationsmanagerservice.NotificationsManager,
typeof _adminusersqueriesservice.AdminUsersQueries === "undefined" ? Object : _adminusersqueriesservice.AdminUsersQueries
])
], AdminService);
//# sourceMappingURL=admin.service.js.map