MCPcopy
hub / github.com/LibreScore/dl-librescore / getFileUrl

Function getFileUrl

src/file.ts:196–243  ·  view source on GitHub ↗
(
    id: number,
    type: FileType,
    scoreUrl = "",
    index = 0,
    _fetch = getFetch(),
    setText?: (str: string) => void,
    pageCount?: number
)

Source from the content-addressed store, hash-verified

194};
195
196export const getFileUrl = async (
197 id: number,
198 type: FileType,
199 scoreUrl = "",
200 index = 0,
201 _fetch = getFetch(),
202 setText?: (str: string) => void,
203 pageCount?: number
204): Promise<string> => {
205 const url = getApiUrl(id, type, index);
206 let auth = await getApiAuth(id, type, index, scoreUrl);
207 if (setText && pageCount) {
208 const percent = Math.round(((index + 1) / pageCount) * 83);
209 setText(`${percent}%`);
210 }
211
212 let r = await _fetch(url, {
213 headers: {
214 Authorization: auth,
215 },
216 });
217
218 if (!r.ok) {
219 auth = md5(`${id}${type}${index}9654,4e`).slice(0, 4);
220 r = await _fetch(url, {
221 headers: {
222 Authorization: auth,
223 },
224 });
225
226 if (!r.ok) {
227 auth = await getApiAuthNetwork(type, index);
228 if (type === "img" && index === 0) {
229 // auth is the URL for the first page
230 r = await _fetch(auth);
231 } else {
232 r = await _fetch(url, {
233 headers: {
234 Authorization: auth,
235 },
236 });
237 }
238 }
239 }
240
241 const { info } = await r.json();
242 return info.url as string;
243};

Callers 3

exportPDFFunction · 0.90
mainFunction · 0.90
cli.tsFile · 0.90

Calls 4

getFetchFunction · 0.90
getApiUrlFunction · 0.85
getApiAuthFunction · 0.85
getApiAuthNetworkFunction · 0.85

Tested by

no test coverage detected