diff --git a/README.md b/README.md index 4a2eb01..c2bfe86 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ const [firstThread] = await twoChannel.fetchThreads("b"); const files = await twoChannel.fetchFiles(firstThread); console.log(files); -// Get all video files from miltiply boards + vendors +// Get all video files from multiply boards + vendors const requiredFileTypes = ["webm", "mp4"]; const twoChannel = twoChannelFactory({ requiredFileTypes }); const fourChannel = fourChannelFactory({ requiredFileTypes }); diff --git a/__tests__/twoChannel/fetchFiles.ts b/__tests__/twoChannel/fetchFiles.ts index 1362f98..7c309b8 100644 --- a/__tests__/twoChannel/fetchFiles.ts +++ b/__tests__/twoChannel/fetchFiles.ts @@ -11,22 +11,22 @@ const fakeResponse = { { posts: [ { + date: "11/01/22 Втр 15:30:53", files: [ { fullname: "full name of jpg file", path: "/test-path.jpg", thumbnail: "/test-thumbnail.jpg", - date: "11/01/22 Втр 15:30:53", }, ], }, { + date: "11/01/22 Втр 15:30:53", files: [ { fullname: "full name of webm file", path: "/test-path.webm", thumbnail: "/test-thumbnail.jpg", - date: "11/01/22 Втр 15:30:53", }, ], }, diff --git a/src/vendors/twoChannel.ts b/src/vendors/twoChannel.ts index c66a558..b9fc373 100644 --- a/src/vendors/twoChannel.ts +++ b/src/vendors/twoChannel.ts @@ -11,7 +11,8 @@ type ThreadsResponse = { type ThreadResponse = { threads: { posts: { - files: [{ fullname: string; path: string; thumbnail: string; date: string }]; + date: string; + files: [{ fullname: string; path: string; thumbnail: string }]; }[]; }[]; }; @@ -47,7 +48,9 @@ export const twoChannelFactory: VendorImplementation = props => { ); const response: ThreadResponse = await fetch(requestUrl).then(r => r.json()); - const rawFiles = response.threads?.[0].posts.map(({ files }) => files).flat(); + const rawFiles = response.threads?.[0].posts + .map(({ files, date }) => files.map(file => ({ ...file, date }))) + .flat(); const files = rawFiles.map(rawFile => ({ url: `https://2ch.hk${rawFile.path}`,