Skip to content

Commit d57d9b6

Browse files
committed
url-compressed-source: Add support for passing the baseFilename instead of deviceType & buildId
Change-type: minor
1 parent ffe085a commit d57d9b6

File tree

1 file changed

+32
-43
lines changed

1 file changed

+32
-43
lines changed

lib/source-destination/url-compressed-source.ts

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,25 @@ import { Dictionary, streamToBuffer } from '../utils';
3535
*/
3636
export interface URLSourceConfig {
3737
VERSION: string; // URL to VERSION file
38-
VERSION_HOSTOS: string; // URL to VERSION_HOSTOS file
3938
'device-type.json': string; // URL to device-type.json file
4039
'image.json': string; // URL to image.json file
4140
parts: Dictionary<string>; // Map of part filenames to their URLs
4241
}
4342

44-
export interface URLCompressedSourceOptions {
43+
export type URLCompressedSourceOptions = {
4544
urls: URLSourceConfig;
4645
format: 'zip' | 'gzip';
47-
filenamePrefix?: string;
4846
configuration?: Dictionary<any>;
49-
deviceType: string; // raspberry-pi
50-
buildId: string; // 2.9.6+rev1.prod
51-
}
47+
} & (
48+
| {
49+
baseFilename: string;
50+
}
51+
| {
52+
filenamePrefix?: string;
53+
deviceType: string; // raspberry-pi
54+
buildId: string; // 2.9.6+rev1.prod
55+
}
56+
);
5257

5358
/**
5459
* URLCompressedSource - Downloads and streams compressed images from direct URLs
@@ -62,12 +67,9 @@ export interface URLCompressedSourceOptions {
6267
* The complete compressed stream is created from the partial compressed files from URLs and the configured parts described above.
6368
*/
6469
export class URLCompressedSource extends SourceDestination {
65-
public readonly deviceType: string;
66-
public readonly buildId: string;
67-
6870
private urls: URLSourceConfig;
6971
private format: URLCompressedSourceOptions['format'];
70-
private filenamePrefix?: string;
72+
private baseFilename?: string;
7173
// configuration is config.json + network configuration + dashboard "when" options like "processorCore" for ts4900
7274
private configuration?: Dictionary<any>;
7375
private configuredParts = new Map<
@@ -79,51 +81,49 @@ export class URLCompressedSource extends SourceDestination {
7981
private imageJSON: ImageJSON;
8082
private deviceTypeJSON: DeviceTypeJSON;
8183
private supervisorVersion: string;
82-
private osVersion: string;
8384
private lastModified: Date;
8485
private size: number;
8586
private filename: string;
8687

8788
constructor({
8889
urls,
8990
format,
90-
filenamePrefix,
9191
configuration,
92-
buildId,
93-
deviceType,
92+
...opts
9493
}: URLCompressedSourceOptions) {
9594
super();
9695
this.urls = urls;
9796
this.format = format;
98-
this.filenamePrefix = filenamePrefix;
97+
98+
this.baseFilename =
99+
'baseFilename' in opts
100+
? opts.baseFilename
101+
: [
102+
opts.filenamePrefix,
103+
opts.deviceType,
104+
opts.buildId.replace(/\.dev$/, ''),
105+
opts.buildId.endsWith('.dev') ? 'dev' : undefined,
106+
]
107+
.filter((p) => p !== undefined)
108+
.join('-');
99109
this.configuration = configuration;
100-
this.buildId = buildId;
101-
this.deviceType = deviceType;
102110
}
103111

104112
private async getSize(): Promise<number> {
105113
return (await this.createStream(true)).zLen;
106114
}
107115

108116
private getFilename(): string {
109-
return [
110-
this.filenamePrefix,
111-
this.deviceType,
112-
this.osVersion,
113-
this.buildId.endsWith('.dev') ? 'dev' : undefined,
114-
this.supervisorVersion,
115-
]
117+
return [this.baseFilename, this.supervisorVersion]
116118
.filter((p) => p !== undefined)
117119
.join('-');
118120
}
119121

120122
protected async _getMetadata(): Promise<Metadata> {
121123
return {
122124
supervisorVersion: this.supervisorVersion,
123-
osVersion: this.osVersion,
124125
lastModified: this.lastModified,
125126
size: this.size,
126-
version: this.buildId,
127127
name: this.filename,
128128
format: this.format,
129129
arch: this.deviceTypeJSON?.arch,
@@ -137,11 +137,6 @@ export class URLCompressedSource extends SourceDestination {
137137
return { supervisorVersion, lastModified };
138138
}
139139

140-
private async getOsVersion() {
141-
const response = await this.download('VERSION_HOSTOS');
142-
return response.data.trim();
143-
}
144-
145140
private async getImageJSON(): Promise<ImageJSON> {
146141
return (await this.download('image.json')).data;
147142
}
@@ -268,24 +263,18 @@ export class URLCompressedSource extends SourceDestination {
268263
throw new Error('Required URLs (VERSION, image.json) must be provided');
269264
}
270265

271-
const [
272-
{ supervisorVersion, lastModified },
273-
osVersion,
274-
imageJSON,
275-
deviceTypeJSON,
276-
] = await Promise.all([
277-
this.getSupervisorVersion(),
278-
this.getOsVersion(),
279-
this.getImageJSON(),
280-
this.getDeviceTypeJSON(),
281-
]);
266+
const [{ supervisorVersion, lastModified }, imageJSON, deviceTypeJSON] =
267+
await Promise.all([
268+
this.getSupervisorVersion(),
269+
this.getImageJSON(),
270+
this.getDeviceTypeJSON(),
271+
]);
282272
if (deviceTypeJSON.yocto.archive) {
283273
// Only zip works for yocto archives (intel-edison)
284274
this.format = 'zip';
285275
}
286276
this.supervisorVersion = supervisorVersion;
287277
this.lastModified = lastModified;
288-
this.osVersion = osVersion;
289278
this.deviceTypeJSON = deviceTypeJSON;
290279
// The order is important, getFilename() expects osVersion and supervisorVersion to be set
291280
this.filename = this.getFilename();

0 commit comments

Comments
 (0)