Skip to content

Commit

Permalink
feat(ProtoUtils): Add support for creating NextParams (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Sep 23, 2024
1 parent 74659fd commit 910c979
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
63 changes: 63 additions & 0 deletions protos/generated/misc/params.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions protos/misc/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,8 @@ message ShortsParam {
}
optional Field1 f1 = 1;
optional int32 p59 = 59;
}

message NextParams {
repeated string video_id = 5;
}
7 changes: 6 additions & 1 deletion src/utils/ProtoUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { base64ToU8, u8ToBase64 } from './Utils.js';
import { VisitorData, PeformCommentActionParams } from '../../protos/generated/misc/params.js';
import { VisitorData, PeformCommentActionParams, NextParams } from '../../protos/generated/misc/params.js';

export function encodeVisitorData(id: string, timestamp: number): string {
const writer = VisitorData.encode({ id, timestamp });
Expand Down Expand Up @@ -45,4 +45,9 @@ export function encodeCommentActionParams(type: number, args: {

const writer = PeformCommentActionParams.encode(data);
return encodeURIComponent(u8ToBase64(writer.finish()));
}

export function encodeNextParams(video_ids: string[]): string {
const writer = NextParams.encode({ videoId: video_ids });
return encodeURIComponent(u8ToBase64(writer.finish()).replace(/\+/g, '-').replace(/\//g, '_'));
}

0 comments on commit 910c979

Please sign in to comment.