Skip to content

Commit

Permalink
Reapply "Removed deprecated loading of remote deck file via URL."
Browse files Browse the repository at this point in the history
This reverts commit 13bea8b.
  • Loading branch information
FelixRilling committed Jan 2, 2024
1 parent b8ebd4e commit 43f1e30
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 67 deletions.
21 changes: 0 additions & 21 deletions src/application/controller/DeckUrlController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ export class DeckUrlController {
* @deprecated
*/
static readonly #PARAM_LEGACY_ENCODED_URI_DECK = "e";
/**
* @deprecated
*/
static readonly #PARAM_REMOTE_DECK = "u";

readonly #deckService: DeckService;
readonly #deckUriEncodingService: DeckUriEncodingService;
Expand All @@ -42,23 +38,6 @@ export class DeckUrlController {
* @return Parsed deck or null if none is found.
*/
async loadUriDeck(url: URL): Promise<Deck | null> {
// Load deck file from a remote URL
const remoteUrlValue = url.searchParams.get(
DeckUrlController.#PARAM_REMOTE_DECK
);
if (remoteUrlValue != null) {
const importResult = await this.#deckFileService.fromRemoteFile(
new URL(location.toString()),
new URL(remoteUrlValue)
);
if (importResult.missing.length > 0) {
DeckUrlController.#logger.warn(
`Could not read ${importResult.missing.length} cards in remote deck.`
);
}
return importResult.deck;
}

// Load encoded URI deck
const uriEncodedDeck = url.searchParams.get(
DeckUrlController.#PARAM_ENCODED_URI_DECK
Expand Down
46 changes: 0 additions & 46 deletions src/core/deck/DeckFileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,52 +30,6 @@ export class DeckFileService {
this.#cardDatabase = cardDatabase;
}

/**
* Loads a deck from a remote .ydk file URL. The name is inferred from the URL.
*
* @param currentUrl The current URL to ensure same-site loading will take place.
* @param remoteUrl URL to load from, MUST be the same origin as currentOrigin.
* @throws Error if origins do not match.
* @return Loaded deck.
* @deprecated
*/
async fromRemoteFile(
currentUrl: URL,
remoteUrl: URL
): Promise<ImportResult> {
if (currentUrl.origin !== remoteUrl.origin) {
throw new Error("Decks can only be loaded from the same origin.");
}

const fileName = this.#getFileNameFromUrl(remoteUrl);
const fileContent = await fetch(remoteUrl, {
method: "GET",
}).then((res) => {
if (res.status != 200) {
throw new Error(`Unexpected status code: ${res.status}`);
}
return res.text();
});
return this.fromFile({
fileName,
fileContent,
});
}

/**
* Gets the file name of a request to a file, or an empty is string if none is found.
*
* @param url URL to check.
* @return File name or empty string.
*/
#getFileNameFromUrl(url: URL): string {
const pathname = url.pathname;
if (!pathname.includes("/")) {
return "";
}
return pathname.substring(pathname.lastIndexOf("/") + 1);
}

/**
* Loads deck from a.ydk file.
*
Expand Down

0 comments on commit 43f1e30

Please sign in to comment.