From a296e691e1e5b9f5f7d8113d2164ce8d736de2b3 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 9 Jul 2024 22:16:38 +0200 Subject: [PATCH] add types & isArray --- .../src/github-folder-resolver.ts | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/libs/remix-url-resolver/src/github-folder-resolver.ts b/libs/remix-url-resolver/src/github-folder-resolver.ts index 6706111a71..e4d800627a 100644 --- a/libs/remix-url-resolver/src/github-folder-resolver.ts +++ b/libs/remix-url-resolver/src/github-folder-resolver.ts @@ -1,6 +1,23 @@ // eslint-disable-next-line no-unused-vars import axios, { AxiosResponse } from 'axios' +export type GithubItem = { + name: string + path: string + sha: string + size: number + url: string + html_url: string + git_url: string + download_url: string | null + type: 'dir' | 'file' + _links: { + self: string + git: string + html: string + } +} + export const githubFolderResolver = async (url, obj = {}, maxDepth, depth?, rootPath?) => { depth = depth ? depth : 0 const child = await pullFolder(url) @@ -10,9 +27,11 @@ export const githubFolderResolver = async (url, obj = {}, maxDepth, depth?, root const pathParts = pathname.split('/'); const folderPath = pathParts.slice(5).join('/'); rootPath = rootPath || folderPath + + if (!Array.isArray(child)) return obj for (const item of child) { if (item.type === 'file') { - const response: AxiosResponse = await axios.get(item.download_url, { transformResponse: res => res }) + const response: AxiosResponse = await axios.get(item.download_url) obj[item.path.replace(rootPath, '')] = response.data } else if (maxDepth > depth) { // dir @@ -24,7 +43,7 @@ export const githubFolderResolver = async (url, obj = {}, maxDepth, depth?, root const pullFolder = async (url) => { const response = await axios.get('https://ghfolderpull.remixproject.org', { params: { ghfolder: url } }); - const data = await response.data; + const data: Array = await response.data; return data }