Skip to content

Commit

Permalink
fix: fix subject field of thread struct for fourChannel vendor, add d…
Browse files Browse the repository at this point in the history
…ate field to file struct
  • Loading branch information
d0kur0 committed Jan 11, 2022
1 parent 725fab6 commit c7aed80
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
16 changes: 10 additions & 6 deletions __tests__/fourChannel/fetchFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ const fakeResponse = {
{
filename: "jpg file",
ext: ".jpg",
tim: "1",
tim: 1641871483134,
time: 1641871483,
},
{
filename: "webm file",
ext: ".webm",
tim: "2",
tim: 1641871483134,
time: 1641871483,
},
],
};
Expand All @@ -28,17 +30,19 @@ beforeEach(() => {
});

const expectedJPGFile: File = {
url: `https://i.4cdn.org/b/1.jpg`,
url: `https://i.4cdn.org/b/1641871483134.jpg`,
name: "jpg file",
rootThread: fakeThread,
previewUrl: `https://i.4cdn.org/b/1s.jpg`,
previewUrl: `https://i.4cdn.org/b/1641871483134s.jpg`,
date: 1641871483,
};

const expectedWEBMFile: File = {
url: `https://i.4cdn.org/b/2.webm`,
url: `https://i.4cdn.org/b/1641871483134.webm`,
name: "webm file",
rootThread: fakeThread,
previewUrl: `https://i.4cdn.org/b/2s.jpg`,
previewUrl: `https://i.4cdn.org/b/1641871483134s.jpg`,
date: 1641871483,
};

it("Check fetching files", async () => {
Expand Down
4 changes: 4 additions & 0 deletions __tests__/twoChannel/fetchFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const fakeResponse = {
fullname: "full name of jpg file",
path: "/test-path.jpg",
thumbnail: "/test-thumbnail.jpg",
date: "11/01/22 Втр 15:30:53",
},
],
},
Expand All @@ -25,6 +26,7 @@ const fakeResponse = {
fullname: "full name of webm file",
path: "/test-path.webm",
thumbnail: "/test-thumbnail.jpg",
date: "11/01/22 Втр 15:30:53",
},
],
},
Expand All @@ -44,13 +46,15 @@ const expectedJPGFile: File = {
name: "full name of jpg file",
rootThread: fakeThread,
previewUrl: "https://2ch.hk/test-thumbnail.jpg",
date: 1667305853,
};

const expectedWEBMFile: File = {
url: "https://2ch.hk/test-path.webm",
name: "full name of webm file",
rootThread: fakeThread,
previewUrl: "https://2ch.hk/test-thumbnail.jpg",
date: 1667305853,
};

it("Check fetching files", async () => {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type File = {
name: string;
rootThread: Thread;
previewUrl: string;
date: number;
};

export type Files = File[];
Expand Down
5 changes: 4 additions & 1 deletion src/vendors/fourChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type ThreadResponse = {
ext: string;
filename: string;
tim: number;
time: number;
com: string;
}
];
};
Expand Down Expand Up @@ -56,8 +58,9 @@ export const fourChannelFactory: VendorImplementation = props => {
(rawPost): File => ({
url: `https://i.4cdn.org/${thread.board}/${rawPost.tim}${rawPost.ext}`,
name: rawPost.filename,
rootThread: thread,
rootThread: { ...thread, subject: response.posts?.[0].com || "" },
previewUrl: `https://i.4cdn.org/${thread.board}/${rawPost.tim}s.jpg`,
date: rawPost.time,
})
);

Expand Down
5 changes: 4 additions & 1 deletion src/vendors/twoChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ type ThreadsResponse = {

type ThreadResponse = {
threads: {
posts: { files: [{ fullname: string; path: string; thumbnail: string }] }[];
posts: {
files: [{ fullname: string; path: string; thumbnail: string; date: string }];
}[];
}[];
};

Expand Down Expand Up @@ -52,6 +54,7 @@ export const twoChannelFactory: VendorImplementation = props => {
name: rawFile.fullname,
rootThread: thread,
previewUrl: `https://2ch.hk${rawFile.thumbnail}`,
date: +new Date(rawFile.date.replace(/\s(.+)\s/, " ")) / 1000 || 0,
}));

if (!props?.requiredFileTypes) return files;
Expand Down

0 comments on commit c7aed80

Please sign in to comment.