Skip to content

Commit

Permalink
fix timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
piloking committed Nov 3, 2024
1 parent d2808e6 commit 4daffa7
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 30 deletions.
4 changes: 2 additions & 2 deletions packages/linejs/client/clients/base-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class BaseClient extends TypedEventEmitter<ClientEvents> {
? "ANDROID"
: "IOSIPAD"
: "IOSIPAD");
const details = await getDeviceDetails(device, options.deviceMap || {});
const details = getDeviceDetails(device, options.deviceMap || {});

if (!details) {
throw new InternalError("Unsupported device", `'${device}'`);
Expand Down Expand Up @@ -787,7 +787,7 @@ export class BaseClient extends TypedEventEmitter<ClientEvents> {
* @description Will override.
*/
public async reactToMessage(_options: {
messageId: bigint|number;
messageId: bigint | number;
reactionType: LINETypes.MessageReactionType;
}): Promise<LINETypes.ReactToMessageResponse> {
return (await Symbol("Unreachable")) as LooseType;
Expand Down
50 changes: 28 additions & 22 deletions packages/linejs/client/clients/timeline/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { LooseType } from "../../entities/common.ts";
import { SettingsClient } from "../internal/setting-client.ts";
import type { TimelineResponse } from "../../entities/timeline.ts";

export class Timeline extends SettingsClient {
protected timelineToken: string | undefined;
Expand All @@ -14,21 +15,20 @@ export class Timeline extends SettingsClient {
await this.approveChannelAndIssueChannelToken({ channelId: "1341209850" })
).channelAccessToken;
this.timelineHeaders = {
Host: "gw.line.naver.jp",
host: this.endpoint,
"x-line-bdbtemplateversion": "v1",
"x-lsr": "JP",
"user-agent": this.system?.userAgent as string,
"user-agent": this.system!.userAgent,
"x-line-channeltoken": this.timelineToken,
"accept-encoding": "gzip",
"x-line-global-config":
"discover.enable=true; follow.enable=true; reboot.phase=scenario",
"x-line-mid": this.user?.mid as string,
"x-line-access": this.metadata?.authToken as string,
"x-line-mid": this.user!.mid,
"x-line-access": this.metadata!.authToken,
"content-type": "application/json; charset=UTF-8",
"x-line-application": this.system?.type as string,
"x-line-application": this.system!.type,
"x-lal": "ja_JP",
"x-lpv": "1",
"x-lap": "5",
};
}

Expand All @@ -50,7 +50,7 @@ export class Timeline extends SettingsClient {
mediaObjectIds?: string[];
mediaObjectTypes?: string[];
sourceType?: string;
}): Promise<LooseType> {
}): Promise<TimelineResponse> {
await this.initTimeline();
const {
homeId,
Expand Down Expand Up @@ -160,15 +160,15 @@ export class Timeline extends SettingsClient {
"Content-type": "application/json",
};
return this.customFetch(
`https://${this.endpoint}/mh/api/v57/post/create.json?${params}`,
`https://${this.endpoint}/${homeId[0] == "s" ? "sn" : "mh"}/api/v57/post/create.json?${params}`,
{ headers, body: JSON.stringify(data), method: "POST" },
).then((r) => r.json());
}

public async deletePost(options: {
homeId: string;
postId: string;
}): Promise<LooseType> {
}): Promise<TimelineResponse> {
await this.initTimeline();
const { homeId, postId } = { ...options };
const headers = {
Expand All @@ -181,15 +181,15 @@ export class Timeline extends SettingsClient {
postId,
});
return this.customFetch(
`https://${this.endpoint}/mh/api/v57/post/delete.json?${params}`,
{ headers, method: "POST" },
`https://${this.endpoint}/${homeId[0] == "s" ? "sn" : "mh"}/api/v57/post/delete.json?${params}`,
{ headers, method: "GET" },
).then((r) => r.json());
}

public async getPost(options: {
homeId: string;
postId: string;
}): Promise<LooseType> {
}): Promise<TimelineResponse> {
await this.initTimeline();
const { homeId, postId } = { ...options };
const headers = {
Expand All @@ -202,7 +202,7 @@ export class Timeline extends SettingsClient {
postId,
});
return this.customFetch(
`https://${this.endpoint}/mh/api/v57/post/get.json?${params}`,
`https://${this.endpoint}/${homeId[0] == "s" ? "sn" : "mh"}/api/v57/post/get.json?${params}`,
{ headers },
).then((r) => r.json());
}
Expand All @@ -212,7 +212,7 @@ export class Timeline extends SettingsClient {
postId?: string;
updatedTime?: number;
sourceType?: string;
}): Promise<LooseType> {
}): Promise<TimelineResponse> {
await this.initTimeline();
const { homeId, postId, updatedTime, sourceType } = {
sourceType: "TALKROOM",
Expand All @@ -221,27 +221,33 @@ export class Timeline extends SettingsClient {
const headers = {
...this.timelineHeaders,
"x-lhm": "GET",
"Content-type": "application/json",
};
const data: Record<string, string> = { homeId, sourceType };
const data: Record<string, string> = {
homeId,
sourceType,
likeLimit: "0",
commentLimit: "0"
};
if (postId) {
data.postId = postId;
}
if (updatedTime) {
data.updatedTime = updatedTime.toString();
}
const params = new URLSearchParams(data);
console.log(params.toString())
return this.customFetch(
`https://${this.endpoint}/mh/api/v57/post/list.json?${params}`,
`https://${this.endpoint}/${homeId[0] == "s" ? "sn" : "mh"}/api/v57/post/list.json?${params}`,
{ headers },
).then((r) => r.json());
}

public async sharePost(options: {
postId: string,
chatMid: string
}) {
const { chatMid, postId, } = {
chatMid: string,
homeId: string,
}): Promise<TimelineResponse> {
const { chatMid, postId, homeId } = {
...options
}
await this.initTimeline();
Expand All @@ -251,14 +257,14 @@ export class Timeline extends SettingsClient {
"Content-type": "application/json",
};
return this.customFetch(
`https://${this.endpoint}/sn/api/v57/post/sendPostToTalk.json`,
`https://${this.endpoint}/${homeId[0] == "s" ? "sn" : "mh"}/api/v57/post/sendPostToTalk.json`,
{
method: "POST",
headers,
body: JSON.stringify({
"postId": postId,
"receiveMids": [chatMid],
}),
})
}).then((r) => r.json());
}
}
4 changes: 3 additions & 1 deletion packages/linejs/client/entities/device.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type Device =
| "DESKTOPWIN"
| "DESKTOPMAC"
| "CHROMEOS"
// | "CHROMEOS"
| "ANDROID"
| "IOS"
| "IOSIPAD"
Expand Down Expand Up @@ -41,6 +41,7 @@ export function getDeviceDetails(
}
systemName = "MAC";
break;
/*
case "CHROMEOS":
appVersion = "3.0.3";
if (deviceMap[device]) {
Expand All @@ -49,6 +50,7 @@ export function getDeviceDetails(
systemName = "Chrome_OS";
systemVersion = "1";
break;
*/
case "ANDROID":
appVersion = "13.4.1";
if (deviceMap[device]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/linejs/client/entities/square-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class SquareChat extends TypedEventEmitter<SquareChatEvents> {
super();
const { squareChat, squareChatMember, squareChatStatus } = rawSouce;
this.mid = squareChat.squareChatMid;
this.squareMid = squareChat.squareChatMid;
this.squareMid = squareChat.squareMid;
this.type = squareChat.type;
this.name = squareChat.name;
this.chatImageObsHash = squareChat.chatImageObsHash;
Expand Down
7 changes: 4 additions & 3 deletions packages/linejs/client/entities/talk-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ export class Note {
return this.client.deletePost(options as LooseType);
}

public listPost(options?: {
public listPost(options: {
homeId?: string;
postId?: string;
updatedTime?: number;
sourceType?: string;
}): Promise<LooseType> {
} = {}): Promise<LooseType> {
(options as LooseType).homeId = this.mid;
return this.client.listPost(options as LooseType);
}
Expand All @@ -121,7 +121,8 @@ export class Note {
postId: string;
chatMid: string;
}) {
return this.client.sharePost(options);
(options as LooseType).homeId = this.mid;
return this.client.sharePost(options as LooseType);
}
}

Expand Down
6 changes: 6 additions & 0 deletions packages/linejs/client/entities/timeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// deno-lint-ignore no-explicit-any
export type TimelineResponse<T = any> = {
code: number,
message: string,
result: T,
}
3 changes: 2 additions & 1 deletion packages/linejs/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"./client": "./client/index.ts",
"./utils": "./utils/index.ts",
"./storage": "./storage/index.ts",
"./rate-limit": "./rate-limit/index.ts"
"./rate-limit": "./rate-limit/index.ts",
"./class": "./client/entities/class.ts"
}
}

0 comments on commit 4daffa7

Please sign in to comment.