Skip to content

Commit

Permalink
fix: fix typo in readme, fix date field location of twoChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
d0kur0 committed Jan 11, 2022
1 parent 9ee5573 commit 57c65ca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
4 changes: 2 additions & 2 deletions __tests__/twoChannel/fetchFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
},
Expand Down
7 changes: 5 additions & 2 deletions src/vendors/twoChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }];
}[];
}[];
};
Expand Down Expand Up @@ -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<File>(rawFile => ({
url: `https://2ch.hk${rawFile.path}`,
Expand Down

0 comments on commit 57c65ca

Please sign in to comment.