Skip to content

Commit

Permalink
Add constants for pathnames
Browse files Browse the repository at this point in the history
  • Loading branch information
Davilarek committed May 21, 2024
1 parent c2f1656 commit 898832f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
* [TekstowoAPI](#TekstowoAPI)
* [new TekstowoAPI(FetchImpl, proxyMetod)](#new_TekstowoAPI_new)
* [.FetchImpl](#TekstowoAPI+FetchImpl) : <code>fetch</code>
* [.ConstantURLPaths](#TekstowoAPI+ConstantURLPaths) : <code>ConstantURLPaths</code>
* [.makeRequest(options)](#TekstowoAPI+makeRequest) ⇒ <code>Promise.&lt;Response&gt;</code>
* [.proxyThisUrl(url)](#TekstowoAPI+proxyThisUrl) ⇒ <code>string</code>
* [.extractLyrics(songId, options)](#TekstowoAPI+extractLyrics) ⇒ <code>Promise.&lt;(TekstowoAPILyrics\|null)&gt;</code>
Expand All @@ -136,6 +137,10 @@ Creates a new TekstowoAPI instance

### tekstowoAPI.FetchImpl : <code>fetch</code>
**Kind**: instance property of [<code>TekstowoAPI</code>](#TekstowoAPI)
<a name="TekstowoAPI+ConstantURLPaths"></a>

### tekstowoAPI.ConstantURLPaths : <code>ConstantURLPaths</code>
**Kind**: instance property of [<code>TekstowoAPI</code>](#TekstowoAPI)
<a name="TekstowoAPI+makeRequest"></a>

### tekstowoAPI.makeRequest(options) ⇒ <code>Promise.&lt;Response&gt;</code>
Expand Down
27 changes: 21 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,19 @@ const AutomaticSortDirection = (sortMode) => {
return SortDirection.descending;
};

const ConstantURLPaths = {
song: "piosenka",
search: "szukaj",
artistSongs: "piosenki_artysty",
};

const TekstowoAPIUrls = {
/**
* @param {TekstowoAPILyricsID} id
*/
LYRICS: (id) => { return `https://www.tekstowo.pl/piosenka,${id}.html`; },
LYRICS: (id) => { return `https://www.tekstowo.pl/${ConstantURLPaths.song},${id}.html`; },
SEARCH: (query, page = 1) => {
let baseUrl = `https://www.tekstowo.pl/szukaj,`;
let baseUrl = `https://www.tekstowo.pl/${ConstantURLPaths.search},`;
baseUrl += query + ",";
baseUrl += "strona," + page;
return baseUrl + ".html";
Expand All @@ -117,7 +123,7 @@ const TekstowoAPIUrls = {
* @param {TekstowoAPIArtistID} id
*/
ARTIST_SONGS: (id, sortMode = SortMode.alphabetically, sortDir = (AutomaticSortDirection(sortMode)), page = 1) => {
return `https://www.tekstowo.pl/piosenki_artysty,${id},${sortMode},${sortDir},strona,${page}.html`;
return `https://www.tekstowo.pl/${ConstantURLPaths.artistSongs},${id},${sortMode},${sortDir},strona,${page}.html`;
},
__TEKSTOWO_OFFICIAL_API_USE_RARELY: {
MORE_COMMENTS: (internalSongId, offset = 0) => {
Expand Down Expand Up @@ -179,6 +185,15 @@ class TekstowoAPI {
SortMode,
SortDirection,
};
/**
* @type {ConstantURLPaths}
*/
this.ConstantURLPaths = null;
Object.defineProperty(this, "ConstantURLPaths", {
get() {
return ConstantURLPaths;
},
});
}
/**
* Makes a request using TekstowoAPI#FetchImpl.
Expand Down Expand Up @@ -359,7 +374,7 @@ class TekstowoAPI {
* @type {Object.<string, TekstowoAPILyricsID>}
*/
const base2 = {};
const splitTarget = `<a href="/piosenka,`;
const splitTarget = `<a href="/${ConstantURLPaths.song},`;
const extractedIds = getTextBetween(rawSongs, splitTarget, `.html" class="`);
for (let i = 0; i < extractedIds.length; i++) {
const element = extractedIds[i];
Expand All @@ -375,7 +390,7 @@ class TekstowoAPI {
* @type {Object.<string, TekstowoAPIArtistID>}
*/
const base2 = {};
const splitTarget = `<a href="/piosenki_artysty,`;
const splitTarget = `<a href="/${ConstantURLPaths.artistSongs},`;
const extractedIds = getTextBetween(rawArtists, splitTarget, `.html" class="`);
for (let i = 0; i < extractedIds.length; i++) {
const element = extractedIds[i];
Expand Down Expand Up @@ -522,7 +537,7 @@ class TekstowoAPI {
* @type {Array<KVPair<string, TekstowoAPIArtistID>>}
*/
const base2 = [];
const splitTarget = `<a href="/piosenka,`;
const splitTarget = `<a href="/${ConstantURLPaths.song},`;
const extractedIds = getTextBetween(base, splitTarget, `.html" class="`);
for (let i = 0; i < extractedIds.length; i++) {
const element = extractedIds[i];
Expand Down

0 comments on commit 898832f

Please sign in to comment.