|
1 | 1 | // deno-lint-ignore-file no-explicit-any |
2 | 2 | import type { BaseClient } from "../mod.ts"; |
| 3 | +import type { LooseType } from "@evex/loose-types"; |
3 | 4 |
|
4 | | -export type TimelineResponse<T = any> = { |
| 5 | +export type TimelineResponse<T = LooseType> = { |
5 | 6 | code: number; |
6 | 7 | message: string; |
7 | 8 | result: T; |
@@ -102,7 +103,7 @@ export class Timeline { |
102 | 103 | homeId: homeId, |
103 | 104 | sourceType: sourceType, |
104 | 105 | }); |
105 | | - const postInfo: any = { |
| 106 | + const postInfo: LooseType = { |
106 | 107 | readPermission: { |
107 | 108 | type: readPermissionType, |
108 | 109 | gids: readPermissionGids, |
@@ -146,7 +147,7 @@ export class Timeline { |
146 | 147 | obsFace: "[]", |
147 | 148 | }); |
148 | 149 | }); |
149 | | - const contents: any = { |
| 150 | + const contents: LooseType = { |
150 | 151 | contentsStyle: { |
151 | 152 | textStyle: { |
152 | 153 | textSizeMode: textSizeMode, |
@@ -260,7 +261,216 @@ export class Timeline { |
260 | 261 | { headers }, |
261 | 262 | ).then((r) => r.json()); |
262 | 263 | } |
| 264 | + |
| 265 | + public async updatePost(options: { |
| 266 | + homeId: string; |
| 267 | + postId: string; |
| 268 | + text?: string; |
| 269 | + sharedPostId?: string; |
| 270 | + textSizeMode?: "AUTO" | "NORMAL"; |
| 271 | + backgroundColor?: string; |
| 272 | + textAnimation?: "NONE" | "SLIDE" | "ZOOM" | "BUZZ" | "BOUNCE" | "BLINK"; |
| 273 | + holdingTime?: number; |
| 274 | + stickerIds?: string[]; |
| 275 | + stickerPackageIds?: string[]; |
| 276 | + locationLatitudes?: number[]; |
| 277 | + locationLongitudes?: number[]; |
| 278 | + locationNames?: string[]; |
| 279 | + mediaObjectIds?: string[]; |
| 280 | + mediaObjectTypes?: string[]; |
| 281 | + }): Promise<TimelineResponse> { |
| 282 | + await this.initTimeline(); |
| 283 | + const { |
| 284 | + homeId, |
| 285 | + postId, |
| 286 | + text, |
| 287 | + sharedPostId, |
| 288 | + textSizeMode, |
| 289 | + backgroundColor, |
| 290 | + textAnimation, |
| 291 | + holdingTime, |
| 292 | + stickerIds, |
| 293 | + stickerPackageIds, |
| 294 | + locationLatitudes, |
| 295 | + locationLongitudes, |
| 296 | + locationNames, |
| 297 | + mediaObjectIds, |
| 298 | + mediaObjectTypes, |
| 299 | + } = { |
| 300 | + textSizeMode: "NORMAL", |
| 301 | + backgroundColor: "#FFFFFF", |
| 302 | + textAnimation: "NONE", |
| 303 | + stickerIds: [], |
| 304 | + stickerPackageIds: [], |
| 305 | + locationLatitudes: [], |
| 306 | + locationLongitudes: [], |
| 307 | + locationNames: [], |
| 308 | + mediaObjectIds: [], |
| 309 | + mediaObjectTypes: [], |
| 310 | + ...options, |
| 311 | + }; |
| 312 | + if (!homeId) { |
| 313 | + throw new Error("homeId is required"); |
| 314 | + } |
| 315 | + if (!postId) { |
| 316 | + throw new Error("postId is required"); |
| 317 | + } |
| 318 | + const postInfo: LooseType = { |
| 319 | + postId: postId, |
| 320 | + editableContents: ["ALL"], |
| 321 | + readPermission: { |
| 322 | + homeID: homeId, |
| 323 | + }, |
| 324 | + }; |
| 325 | + const stickers: { |
| 326 | + id: string; |
| 327 | + packageId: string; |
| 328 | + packageVersion: number; |
| 329 | + hasAnimation: boolean; |
| 330 | + hasSound: boolean; |
| 331 | + stickerResourceType: string; |
| 332 | + }[] = []; |
| 333 | + const locations: { |
| 334 | + latitude: number; |
| 335 | + longitude: number; |
| 336 | + name: string; |
| 337 | + }[] = []; |
| 338 | + const medias: { objectId: string; type: string; obsFace: string }[] = []; |
| 339 | + stickerIds.forEach((stickerId, stickerIndex) => { |
| 340 | + stickers.push({ |
| 341 | + id: stickerId, |
| 342 | + packageId: stickerPackageIds[stickerIndex], |
| 343 | + packageVersion: 1, |
| 344 | + hasAnimation: true, |
| 345 | + hasSound: true, |
| 346 | + stickerResourceType: "ANIMATION", |
| 347 | + }); |
| 348 | + }); |
| 349 | + locationLatitudes.forEach((locationLatitude, locatioIndex) => { |
| 350 | + locations.push({ |
| 351 | + latitude: locationLatitude, |
| 352 | + longitude: locationLongitudes[locatioIndex], |
| 353 | + name: locationNames[locatioIndex], |
| 354 | + }); |
| 355 | + }); |
| 356 | + mediaObjectIds.forEach((mediaObjectId, mediaIndex) => { |
| 357 | + medias.push({ |
| 358 | + objectId: mediaObjectId, |
| 359 | + type: mediaObjectTypes[mediaIndex], |
| 360 | + obsFace: "[]", |
| 361 | + }); |
| 362 | + }); |
| 363 | + const contents: LooseType = { |
| 364 | + sticonMetas: [], |
| 365 | + contentsStyle: { |
| 366 | + textStyle: textSizeMode || textAnimation ? { |
| 367 | + textSizeMode: textSizeMode, |
| 368 | + textAnimation: textAnimation, |
| 369 | + } : {}, |
| 370 | + stickerStyle: backgroundColor ? { |
| 371 | + backgroundColor: backgroundColor, |
| 372 | + } : {}, |
| 373 | + mediaStyle: {}, |
| 374 | + }, |
| 375 | + stickers: stickers, |
| 376 | + textMeta: [], |
| 377 | + locations: locations, |
| 378 | + media: medias, |
| 379 | + }; |
| 380 | + if (typeof holdingTime !== "undefined") { |
| 381 | + postInfo.holdingTime = holdingTime; |
| 382 | + } |
| 383 | + if (typeof text !== "undefined") { |
| 384 | + contents.text = text; |
| 385 | + } |
| 386 | + if (typeof sharedPostId !== "undefined") { |
| 387 | + contents.sharedPostId = sharedPostId; |
| 388 | + } |
| 389 | + const data = { postInfo: postInfo, contents: contents }; |
| 390 | + const params = new URLSearchParams({ |
| 391 | + homeId: homeId, |
| 392 | + }); |
| 393 | + const headers = { |
| 394 | + ...this.timelineHeaders, |
| 395 | + "x-lhm": "POST", |
| 396 | + }; |
| 397 | + return await this.client.fetch( |
| 398 | + `https://${this.client.request.endpoint}/${ |
| 399 | + homeId[0] == "s" ? "sn" : "mh" |
| 400 | + }/api/v57/post/update.json?${params}`, |
| 401 | + { headers, body: JSON.stringify(data), method: "POST" }, |
| 402 | + ).then((r) => r.json()); |
| 403 | + } |
| 404 | + |
| 405 | + public async likePost(options: { |
| 406 | + contentId: string; // postId |
| 407 | + homeId: string; |
| 408 | + likeType?: "1003" | "1001" | "1002" | "1004" | "1006" | "1005"; // 1003: GOOD, 1001: LOVE, 1002: FUNNY, 1004: AMAZING, 1006: SAD, 1005: SURPRISED |
| 409 | + sourceType?: string; |
| 410 | + }): Promise<TimelineResponse> { |
| 411 | + await this.initTimeline(); |
| 412 | + const { contentId, homeId, likeType, sourceType } = { |
| 413 | + likeType: "1003", |
| 414 | + sourceType: "TIMELINE", |
| 415 | + ...options, |
| 416 | + }; |
| 417 | + const params = new URLSearchParams({ |
| 418 | + homeId, |
| 419 | + }); |
| 420 | + const headers = { |
| 421 | + ...this.timelineHeaders, |
| 422 | + "x-lhm": "POST", |
| 423 | + }; |
| 424 | + return await this.client.fetch( |
| 425 | + `https://${this.client.request.endpoint}/ext/note/nt/api/v57/like/create.json?${params}`, |
| 426 | + { |
| 427 | + headers, |
| 428 | + method: "POST", |
| 429 | + body: JSON.stringify({ |
| 430 | + sourceType, |
| 431 | + likeType, |
| 432 | + contentId, |
| 433 | + }), |
| 434 | + }, |
| 435 | + ).then((r) => r.json()); |
| 436 | + } |
263 | 437 |
|
| 438 | + public async createComment(options: { |
| 439 | + contentId: string; // postId |
| 440 | + commentText: string; |
| 441 | + homeId: string; |
| 442 | + sourceType?: string; |
| 443 | + contentsList?: LooseType[]; |
| 444 | + }): Promise<TimelineResponse> { |
| 445 | + await this.initTimeline(); |
| 446 | + const { contentId, commentText, homeId, sourceType, contentsList } = { |
| 447 | + sourceType: "TIMELINE", |
| 448 | + contentsList: [], |
| 449 | + ...options, |
| 450 | + }; |
| 451 | + const params = new URLSearchParams({ |
| 452 | + sourceType, |
| 453 | + homeId, |
| 454 | + }); |
| 455 | + const headers = { |
| 456 | + ...this.timelineHeaders, |
| 457 | + "x-lhm": "POST", |
| 458 | + }; |
| 459 | + const body = { |
| 460 | + commentText, |
| 461 | + contentId, |
| 462 | + contentsList, |
| 463 | + }; |
| 464 | + return await this.client.fetch( |
| 465 | + `https://${this.client.request.endpoint}/ext/note/nt/api/v57/comment/create.json?${params}`, |
| 466 | + { |
| 467 | + headers, |
| 468 | + method: "POST", |
| 469 | + body: JSON.stringify(body), |
| 470 | + }, |
| 471 | + ).then((r) => r.json()); |
| 472 | + } |
| 473 | + |
264 | 474 | public async sharePost(options: { |
265 | 475 | postId: string; |
266 | 476 | chatMid: string; |
|
0 commit comments