feat: finalize protobuf encoder for comment translations

This commit is contained in:
LuanRT
2022-05-01 17:49:23 -03:00
parent 7e8a517de9
commit 29897981f0
2 changed files with 35 additions and 7 deletions

View File

@@ -96,10 +96,21 @@ class Actions {
data.commentText = args.text;
break;
case 'comment/perform_comment_action':
const params = {
video_id: args.video_id,
comment_id: args.comment_id
};
const target_action = ({
like: () => Proto.encodeCommentActionParams(5, args.comment_id, args.video_id),
dislike: () => Proto.encodeCommentActionParams(4, args.comment_id, args.video_id),
like: () => Proto.encodeCommentActionParams(5, params),
dislike: () => Proto.encodeCommentActionParams(4, params),
translate: () => {
params.text = args.text;
params.target_language = args.target_language;
return Proto.encodeCommentActionParams(22, params);
}
})[args.comment_action]();
data.actions = [ target_action ];
break;
default:

View File

@@ -142,19 +142,36 @@ class Proto {
* @param {string} type
* @param {string} comment_id
* @param {string} video_id
* @param {string} [text]
* @param {string} [target_language]
*
* @returns {string}
*/
static encodeCommentActionParams(type, comment_id, video_id) {
const buf = messages.PeformCommentActionParams.encode({
type, comment_id, video_id,
static encodeCommentActionParams(type, args = {}) {
const data = {
type,
comment_id: args.comment_id,
video_id: args.video_id,
/* Maybe these can be safely removed? */
unk_num: 2, unk_num_1: 0, unk_num_2: 0,
unk_num_3: "0", unk_num_4: 0,
unk_num_5: 12, unk_num_6: 0,
});
}
if (args.hasOwnProperty('text')) {
data.translate_comment_params = {
params: {
comment: {
text: args.text
}
},
comment_id: args.comment_id,
target_language: args.target_language
}
}
const buf = messages.PeformCommentActionParams.encode(data);
return encodeURIComponent(Buffer.from(buf).toString('base64'));
}