forked from xdarklight/cm-update-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget-target-file-zipnames.js
56 lines (50 loc) · 1.37 KB
/
get-target-file-zipnames.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var Troll = require('troll-opt').Troll;
var models = require('./models/');
var buildInfo = (new Troll()).options(function(troll) {
troll.banner('Outputs all target-files zip names (one per line) for all builds that match the given device / subdirectory.');
troll.opt('device', 'The device ID.', { type: 'string', required: true });
troll.opt('subdirectory', 'The subdirectory from which the file can be downloaded.', { type: 'string' });
troll.opt('max_age_days', 'The max age (according to a Rom\' timestamp) of the target files in days.', { type: 'integer' });
});
var minDate = new Date(-8640000000000000);
models.sequelize.sync().then(function() {
var startTimestamp;
if (!buildInfo.max_age_days || isNaN(buildInfo.max_age_days)) {
startTimestamp = minDate;
} else {
startTimestamp = new Date();
startTimestamp.setHours(-24 * buildInfo.max_age_days);
}
models.Rom.findAll({
include: [
{
model: models.RomVariant,
include: [
{
model: models.Device,
where: {
name: buildInfo.device,
}
},
],
where: {
subdirectory: buildInfo.subdirectory
}
}
],
where: {
timestamp: {
gt: startTimestamp,
},
targetFilesZipName: {
ne: null,
},
},
}).then(function(roms) {
roms.forEach(function(rom) {
if (rom.targetFilesZipName.length > 0) {
console.log(rom.targetFilesZipName);
}
});
});
});