update
This commit is contained in:
120
src/api.js
120
src/api.js
@@ -61,7 +61,7 @@ const getBucketFiles = async (folderName) => {
|
|||||||
|
|
||||||
const contents = Array.isArray(data?.Contents) ? data.Contents : [];
|
const contents = Array.isArray(data?.Contents) ? data.Contents : [];
|
||||||
|
|
||||||
// Normalize + sort newest first (for retention + build ordering)
|
// Normalize + newest-first
|
||||||
const ret = contents
|
const ret = contents
|
||||||
.filter((obj) => obj.Key !== folderKey)
|
.filter((obj) => obj.Key !== folderKey)
|
||||||
.map((obj) => {
|
.map((obj) => {
|
||||||
@@ -88,16 +88,16 @@ const getBucketFiles = async (folderName) => {
|
|||||||
.sort((a, b) => (a.sort > b.sort ? -1 : a.sort < b.sort ? 1 : 0));
|
.sort((a, b) => (a.sort > b.sort ? -1 : a.sort < b.sort ? 1 : 0));
|
||||||
|
|
||||||
const byKey = Object.fromEntries(ret.map((r) => [r.key, r]));
|
const byKey = Object.fromEntries(ret.map((r) => [r.key, r]));
|
||||||
const ext = ".tar.gz";
|
const TAR = ".tar.gz";
|
||||||
|
|
||||||
// Choose base tars; retention (nightly) still per product_platform_arch
|
// Keep only tar anchors (apply nightly retention)
|
||||||
const tars = ret.filter((it) => it.name.endsWith(ext));
|
const tars = ret.filter((it) => it.name.endsWith(TAR));
|
||||||
const keepTarKeys = new Set();
|
const keepTarKeys = new Set();
|
||||||
const itemCount = {};
|
const itemCount = {};
|
||||||
|
|
||||||
for (const t of tars) {
|
for (const t of tars) {
|
||||||
if (folderName === "nightly") {
|
if (folderName === "nightly") {
|
||||||
const parts = t.name.split("_"); // 0=product 1=version 2=build 3=platform 4=arch
|
const parts = t.name.split("_"); // 0=product,1=version,2=build,3=platform,4=arch
|
||||||
const groupId = `${parts[0]}_${parts[3]}_${parts[4]}`;
|
const groupId = `${parts[0]}_${parts[3]}_${parts[4]}`;
|
||||||
itemCount[groupId] = itemCount[groupId] || 0;
|
itemCount[groupId] = itemCount[groupId] || 0;
|
||||||
|
|
||||||
@@ -108,17 +108,15 @@ const getBucketFiles = async (folderName) => {
|
|||||||
if (!oldItems.includes(t.key)) {
|
if (!oldItems.includes(t.key)) {
|
||||||
oldItems.push(t.key, t.key + ".sha256", t.key + ".sig");
|
oldItems.push(t.key, t.key + ".sha256", t.key + ".sig");
|
||||||
}
|
}
|
||||||
// mark companions old if present
|
// companions old
|
||||||
if (parts[3] === "windows") {
|
if (parts[3] === "windows") {
|
||||||
const setupKey =
|
const setupKey = t.key.slice(0, -TAR.length) + "_setup.exe";
|
||||||
t.key.substring(0, t.key.length - ext.length) + "_setup.exe";
|
|
||||||
if (byKey[setupKey] && !oldItems.includes(setupKey)) {
|
if (byKey[setupKey] && !oldItems.includes(setupKey)) {
|
||||||
oldItems.push(setupKey, setupKey + ".sha256", setupKey + ".sig");
|
oldItems.push(setupKey, setupKey + ".sha256", setupKey + ".sig");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (parts[3] === "darwin") {
|
if (parts[3] === "darwin") {
|
||||||
const dmgKey =
|
const dmgKey = t.key.slice(0, -TAR.length) + ".dmg";
|
||||||
t.key.substring(0, t.key.length - ext.length) + ".dmg";
|
|
||||||
if (byKey[dmgKey] && !oldItems.includes(dmgKey)) {
|
if (byKey[dmgKey] && !oldItems.includes(dmgKey)) {
|
||||||
oldItems.push(dmgKey, dmgKey + ".sha256", dmgKey + ".sig");
|
oldItems.push(dmgKey, dmgKey + ".sha256", dmgKey + ".sig");
|
||||||
}
|
}
|
||||||
@@ -129,85 +127,71 @@ const getBucketFiles = async (folderName) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build -> { maxSort, byPlatArch: Map("platform|arch" -> tarItem) }
|
// Build -> platform/arch -> tar
|
||||||
const builds = new Map();
|
const builds = new Map(); // buildId -> { maxSort, map: Map("platform|arch" -> tarItem) }
|
||||||
|
|
||||||
for (const t of tars) {
|
for (const t of tars) {
|
||||||
if (!keepTarKeys.has(t.key)) continue;
|
if (!keepTarKeys.has(t.key)) continue;
|
||||||
const parts = t.name.split("_");
|
const parts = t.name.split("_");
|
||||||
const buildId = `${parts[0]}|${parts[1]}|${parts[2]}`; // group by 0,1,2
|
const buildId = `${parts[0]}|${parts[1]}|${parts[2]}`; // parts 0..2
|
||||||
const platArch = `${(parts[3] || "").toLowerCase()}|${parts[4] || ""}`; // then 3,4
|
const platform = (parts[3] || "").toLowerCase();
|
||||||
|
const arch = (parts[4] || "").toLowerCase();
|
||||||
|
const platArch = `${platform}|${arch}`;
|
||||||
|
|
||||||
if (!builds.has(buildId)) {
|
if (!builds.has(buildId))
|
||||||
builds.set(buildId, { maxSort: t.sort, byPlatArch: new Map() });
|
builds.set(buildId, { maxSort: t.sort, map: new Map() });
|
||||||
}
|
|
||||||
const bucket = builds.get(buildId);
|
const bucket = builds.get(buildId);
|
||||||
bucket.maxSort = Math.max(bucket.maxSort, t.sort);
|
bucket.maxSort = Math.max(bucket.maxSort, t.sort);
|
||||||
bucket.byPlatArch.set(platArch, t); // 1 tar per plat/arch tuple
|
bucket.map.set(platArch, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Order builds by newest
|
// Sort builds newest-first
|
||||||
const orderedBuilds = Array.from(builds.entries()).sort(
|
const orderedBuilds = Array.from(builds.entries()).sort(
|
||||||
(a, b) => b[1].maxSort - a[1].maxSort,
|
(a, b) => b[1].maxSort - a[1].maxSort,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Inside a build, order platform/arch consistently
|
// Explicit platform/arch order
|
||||||
const platformRank = (p) =>
|
const platformOrder = ["darwin", "windows", "linux"];
|
||||||
p === "darwin" ? 0 : p === "windows" ? 1 : p === "linux" ? 2 : 3;
|
const archOrder = ["aarch64", "arm64", "x86-64", "x86_64"];
|
||||||
const archRank = (a) =>
|
|
||||||
a === "aarch64" || a === "arm64"
|
|
||||||
? 0
|
|
||||||
: a === "x86-64" || a === "x86_64"
|
|
||||||
? 1
|
|
||||||
: 2;
|
|
||||||
|
|
||||||
const out = [];
|
const out = [];
|
||||||
|
|
||||||
for (const [, bucket] of orderedBuilds) {
|
for (const [, bucket] of orderedBuilds) {
|
||||||
const groups = Array.from(bucket.byPlatArch.entries())
|
for (const p of platformOrder) {
|
||||||
.map(([k, tar]) => {
|
for (const a of archOrder) {
|
||||||
const [platform, arch] = k.split("|");
|
const keyPA = `${p}|${a}`;
|
||||||
return { platform, arch, tar };
|
const tar = bucket.map.get(keyPA);
|
||||||
})
|
if (!tar) continue;
|
||||||
.sort((a, b) => {
|
|
||||||
const pr = platformRank(a.platform) - platformRank(b.platform);
|
|
||||||
if (pr !== 0) return pr;
|
|
||||||
const ar = archRank(a.arch) - archRank(b.arch);
|
|
||||||
if (ar !== 0) return ar;
|
|
||||||
return b.tar.sort - a.tar.sort; // stable fallback
|
|
||||||
});
|
|
||||||
|
|
||||||
// Emit each platform/arch group in order: dmg -> setup -> tar (each with sidecars)
|
const base = tar.key.slice(0, -TAR.length);
|
||||||
for (const { platform, tar } of groups) {
|
|
||||||
const base = tar.key.substring(0, tar.key.length - ext.length);
|
|
||||||
|
|
||||||
// 1) DMG (darwin only)
|
// 1) DMG group (darwin only)
|
||||||
if (platform === "darwin") {
|
if (p === "darwin") {
|
||||||
const dmgKey = base + ".dmg";
|
const dmgKey = base + ".dmg";
|
||||||
const dmg = byKey[dmgKey];
|
const dmg = byKey[dmgKey];
|
||||||
if (dmg) {
|
if (dmg) {
|
||||||
out.push(dmg);
|
out.push(dmg);
|
||||||
if (byKey[dmgKey + ".sha256"]) out.push(byKey[dmgKey + ".sha256"]);
|
if (byKey[dmgKey + ".sha256"])
|
||||||
if (byKey[dmgKey + ".sig"]) out.push(byKey[dmgKey + ".sig"]);
|
out.push(byKey[dmgKey + ".sha256"]);
|
||||||
|
if (byKey[dmgKey + ".sig"]) out.push(byKey[dmgKey + ".sig"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 2) SETUP (windows only)
|
// 2) SETUP group (windows only)
|
||||||
if (platform === "windows") {
|
if (p === "windows") {
|
||||||
const setupKey = base + "_setup.exe";
|
const setupKey = base + "_setup.exe";
|
||||||
const setup = byKey[setupKey];
|
const setup = byKey[setupKey];
|
||||||
if (setup) {
|
if (setup) {
|
||||||
out.push(setup);
|
out.push(setup);
|
||||||
if (byKey[setupKey + ".sha256"])
|
if (byKey[setupKey + ".sha256"])
|
||||||
out.push(byKey[setupKey + ".sha256"]);
|
out.push(byKey[setupKey + ".sha256"]);
|
||||||
if (byKey[setupKey + ".sig"]) out.push(byKey[setupKey + ".sig"]);
|
if (byKey[setupKey + ".sig"]) out.push(byKey[setupKey + ".sig"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 3) TAR (always)
|
// 3) TAR group (always)
|
||||||
out.push(tar);
|
out.push(tar);
|
||||||
if (byKey[tar.key + ".sha256"]) out.push(byKey[tar.key + ".sha256"]);
|
if (byKey[tar.key + ".sha256"]) out.push(byKey[tar.key + ".sha256"]);
|
||||||
if (byKey[tar.key + ".sig"]) out.push(byKey[tar.key + ".sig"]);
|
if (byKey[tar.key + ".sig"]) out.push(byKey[tar.key + ".sig"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user