Commit 3dc816e7 authored by nanahira's avatar nanahira

add _latest for latest version reference

parent ac15ab42
Pipeline #5029 passed with stages
in 1 minute and 21 seconds
......@@ -11,6 +11,7 @@ import _ from 'lodash';
import { ArchiveFile } from '../entities/ArchiveFile.entity';
import * as os from 'os';
import moment from 'moment';
import { AppsJson } from '../utility/apps-json-type';
@Injectable()
export class UpdateService extends ConsoleLogger {
......@@ -25,9 +26,49 @@ export class UpdateService extends ConsoleLogger {
}
async getAppsJson() {
return (await this.db.getRepository(App).find({ where: { appData: Not(IsNull()), isDeleted: false }, select: ['appData'] })).map(
const data = (await this.db.getRepository(App).find({ where: { appData: Not(IsNull()), isDeleted: false }, select: ['appData'] })).map(
(a) => a.displayData
);
const appVersionCacheMap = new Map<string, string>();
for (const _platform of Object.values(AppsJson.Platform)) {
const platform = _platform as AppsJson.Platform;
if (platform === 'generic') {
continue;
}
const depotDto = new DepotDto();
depotDto.locale = 'generic';
depotDto.arch = 'generic';
depotDto.platform = platform;
// this.log(platform);
for (const app of data) {
if (app.version && app.version[platform] === '_latest') {
// this.log(`Try fetching latest version of ${app.id} ${platform}`);
const tryCache = appVersionCacheMap.get(app.id);
if (tryCache) {
app.version[platform] = tryCache;
}
const latestBuild = await this.db
.getRepository(Build)
.createQueryBuilder('build')
.select(['build.version', 'build.id', 'depot.platform'])
.innerJoin('build.depot', 'depot')
.where('depot.appId = :appId', { appId: app.id })
.andWhere(depotDto.getQueryBrackets())
.orderBy('build.id', 'DESC')
.take(1)
.getOne();
if (latestBuild) {
const latestVersion = latestBuild.version;
if (latestBuild.depot.platform === 'generic') {
appVersionCacheMap.set(app.id, latestVersion);
}
app.version[platform] = latestVersion;
}
}
}
}
return data;
}
private async getBuild(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment