mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-20 01:33:56 +00:00
ci: fixing release pipeline
This commit is contained in:
@@ -9,6 +9,13 @@ const addDownloadSource = async (
|
||||
url: string
|
||||
) => {
|
||||
try {
|
||||
const existingSources = await downloadSourcesSublevel.values().all();
|
||||
const urlExists = existingSources.some((source) => source.url === url);
|
||||
|
||||
if (urlExists) {
|
||||
throw new Error("Download source with this URL already exists");
|
||||
}
|
||||
|
||||
const downloadSource = await HydraApi.post<DownloadSource>(
|
||||
"/download-sources",
|
||||
{
|
||||
@@ -17,7 +24,7 @@ const addDownloadSource = async (
|
||||
{ needsAuth: false }
|
||||
);
|
||||
|
||||
if (HydraApi.isLoggedIn()) {
|
||||
if (HydraApi.isLoggedIn() && HydraApi.hasActiveSubscription()) {
|
||||
try {
|
||||
await HydraApi.post("/profile/download-sources", {
|
||||
urls: [url],
|
||||
|
||||
@@ -13,7 +13,7 @@ const removeDownloadSource = async (
|
||||
|
||||
if (downloadSourceId) params.set("downloadSourceId", downloadSourceId);
|
||||
|
||||
if (HydraApi.isLoggedIn()) {
|
||||
if (HydraApi.isLoggedIn() && HydraApi.hasActiveSubscription()) {
|
||||
void HydraApi.delete(`/profile/download-sources?${params.toString()}`);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,9 +50,14 @@ export const loadState = async () => {
|
||||
DeckyPlugin.checkAndUpdateIfOutdated();
|
||||
}
|
||||
|
||||
await HydraApi.setupApi().then(() => {
|
||||
await HydraApi.setupApi().then(async () => {
|
||||
uploadGamesBatch();
|
||||
void migrateDownloadSources();
|
||||
|
||||
const { syncDownloadSourcesFromApi } = await import(
|
||||
"./services/user"
|
||||
);
|
||||
void syncDownloadSourcesFromApi();
|
||||
// WSClient.connect();
|
||||
});
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ export class HydraApi {
|
||||
return this.userAuth.authToken !== "";
|
||||
}
|
||||
|
||||
private static hasActiveSubscription() {
|
||||
public static hasActiveSubscription() {
|
||||
const expiresAt = new Date(this.userAuth.subscription?.expiresAt ?? 0);
|
||||
return expiresAt > new Date();
|
||||
}
|
||||
@@ -105,6 +105,9 @@ export class HydraApi {
|
||||
|
||||
// WSClient.close();
|
||||
// WSClient.connect();
|
||||
|
||||
const { syncDownloadSourcesFromApi } = await import("./user");
|
||||
syncDownloadSourcesFromApi();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,3 +18,4 @@ export * from "./library-sync";
|
||||
export * from "./wine";
|
||||
export * from "./lock";
|
||||
export * from "./decky-plugin";
|
||||
export * from "./user";
|
||||
|
||||
3
src/main/services/user/index.ts
Normal file
3
src/main/services/user/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./get-user-data";
|
||||
export * from "./sync-download-sources";
|
||||
|
||||
42
src/main/services/user/sync-download-sources.ts
Normal file
42
src/main/services/user/sync-download-sources.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { HydraApi, logger } from "../";
|
||||
import { downloadSourcesSublevel } from "@main/level";
|
||||
import type { DownloadSource } from "@types";
|
||||
|
||||
export const syncDownloadSourcesFromApi = async () => {
|
||||
if (!HydraApi.isLoggedIn() || !HydraApi.hasActiveSubscription()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const profileSources = await HydraApi.get<DownloadSource[]>(
|
||||
"/profile/download-sources"
|
||||
);
|
||||
|
||||
const existingSources = await downloadSourcesSublevel.values().all();
|
||||
const existingUrls = new Set(existingSources.map((source) => source.url));
|
||||
|
||||
for (const downloadSource of profileSources) {
|
||||
if (!existingUrls.has(downloadSource.url)) {
|
||||
try {
|
||||
await downloadSourcesSublevel.put(downloadSource.id, {
|
||||
...downloadSource,
|
||||
isRemote: true,
|
||||
createdAt: new Date().toISOString(),
|
||||
});
|
||||
|
||||
logger.log(
|
||||
`Synced download source from profile: ${downloadSource.url}`
|
||||
);
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`Failed to sync download source ${downloadSource.url}:`,
|
||||
error
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error("Failed to sync download sources from API:", error);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user