Commit 3a88a7ee authored by nanahira's avatar nanahira

Update console-api/src/s3/s3.service.ts,...

Update console-api/src/s3/s3.service.ts, console-api/src/update/update.service.ts, console-api/src/entities/Archive.entity.ts, console-api/views/metalinks.mustache files
parent 9c117d90
Pipeline #39332 failed with stages
in 5 minutes and 46 seconds
......@@ -54,4 +54,11 @@ export class Archive extends TimeBase {
name: this.archiveFullPath,
};
}
url: string;
fillUrl(cdnUrl: string, cdnUrlOversize: string) {
const useCdn = this.size > 536870912 ? cdnUrlOversize : cdnUrl;
this.url = `${useCdn}/${this.path}.tar.zst`;
}
}
......@@ -28,10 +28,19 @@ export class S3Service extends ConsoleLogger {
return `${this.cdnUrl}/${path}`;
}
getCdnUrlOversize(path: string) {
return `${this.cdnUrlOversize}/${path}`;
}
getCdnUrlAuto(path: string, size: number) {
return size > 536870912 ? this.getCdnUrlOversize(path) : this.getCdnUrl(path);
}
private readonly bucket = this.getConfig('S3_BUCKET');
private readonly prefix = this.getConfig('S3_PREFIX');
public readonly cdnUrl =
this.getConfig('S3_CDN_URL') || `${this.getConfig('S3_ENDPOINT')}/${this.bucket}${this.prefix ? `/${this.prefix}` : ''}`;
public readonly cdnUrlOversize = this.getConfig('S3_CDN_URL_OVERSIZE') || this.cdnUrl;
private readonly s3Config: S3ClientConfig = {
credentials: {
accessKeyId: this.getConfig('S3_KEY'),
......
......@@ -16,6 +16,7 @@ import moment from 'moment';
@Injectable()
export class UpdateService extends ConsoleLogger {
private readonly cdnUrl: string;
private readonly cdnUrlOversize: string;
constructor(
@InjectConnection('app')
private db: Connection,
......@@ -24,6 +25,7 @@ export class UpdateService extends ConsoleLogger {
) {
super('update');
this.cdnUrl = packageS3.cdnUrl;
this.cdnUrlOversize = packageS3.cdnUrlOversize;
}
async getAppsJson() {
......@@ -150,8 +152,8 @@ export class UpdateService extends ConsoleLogger {
throw new BlankReturnMessageDto(404, 'Archive not found').toException();
}
await this.mirror.lookForArchivesMirror(archives, ip);
archives.forEach(a => a.fillUrl(this.cdnUrl, this.cdnUrlOversize));
return {
cdnUrl: this.cdnUrl,
archives,
};
}
......@@ -161,8 +163,8 @@ export class UpdateService extends ConsoleLogger {
qb.select(['archive.hash', 'archive.path', 'archive.size']).andWhere('archive.role = :fullRole', { fullRole: ArchiveType.Full })
);
await this.mirror.lookForArchivesMirror(archives, ip);
archives.forEach(a => a.fillUrl(this.cdnUrl, this.cdnUrlOversize));
return {
cdnUrl: this.cdnUrl,
archives: archives,
};
}
......@@ -251,8 +253,8 @@ export class UpdateService extends ConsoleLogger {
if (!remainingFiles.length) {
// console.log('exact', bestUpdateArchive);
await this.mirror.lookForArchivesMirror([bestUpdateArchive], ip);
bestUpdateArchive.fillUrl(this.cdnUrl, this.cdnUrlOversize);
return {
cdnUrl: this.cdnUrl,
archives: [bestUpdateArchive],
};
}
......@@ -308,8 +310,8 @@ export class UpdateService extends ConsoleLogger {
const archives = _.minBy(packagePlans, (plan) => this.getCostOfArchives(plan));
// console.log('use', archives);
await this.mirror.lookForArchivesMirror(archives, ip);
archives.forEach(a => a.fillUrl(this.cdnUrl, this.cdnUrlOversize));
return {
cdnUrl: this.cdnUrl,
archives,
};
}
......
......@@ -9,7 +9,7 @@
{{#mirrors}}
<url priority="1">{{&.}}</url>
{{/mirrors}}
<url priority="2">{{&cdnUrl}}/{{path}}.tar.zst</url>
<url priority="2">{{&url}}</url>
</file>
{{/archives}}
</metalink>
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