mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 03:07:04 +02:00
feat: new reviews
This commit is contained in:
1 parent
f91dd1e2c0
commit
d9521ce1e5
11 files changed
+196
-188
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import { decode } from '../protobuf/decode';
|
||||
import { asset } from './asset';
|
||||
|
||||
export interface Reviews {
|
||||
reviews: Record<number, Review>;
|
||||
}
|
||||
|
||||
interface Review {
|
||||
last_updated: number;
|
||||
videos?: Video[];
|
||||
}
|
||||
|
||||
export interface Video {
|
||||
id: string;
|
||||
author: string;
|
||||
}
|
||||
|
||||
export const reviews = fetch(asset('definitions/reviews.pb'))
|
||||
.then((response) => response.arrayBuffer())
|
||||
.then((buffer) =>
|
||||
decode<Reviews>('reviews/blitzkit.Reviews', new Uint8Array(buffer)),
|
||||
);
|
||||
@@ -1,32 +0,0 @@
|
||||
import { asset } from './asset';
|
||||
|
||||
export interface VideoDefinitions {
|
||||
[id: number]: {
|
||||
videos: string[];
|
||||
lastUpdated: number;
|
||||
};
|
||||
}
|
||||
|
||||
export const videoDefinitions = fetch(asset('definitions/videos.csv'))
|
||||
.then((response) => response.text())
|
||||
.then((text) =>
|
||||
text
|
||||
.split('\n')
|
||||
.map((line) => {
|
||||
const [idString, lastUpdatedString, ...videos] = line
|
||||
.split(',')
|
||||
.filter(Boolean);
|
||||
const id = Number(idString);
|
||||
const lastUpdated = Number(lastUpdatedString);
|
||||
return { id, videos, lastUpdated };
|
||||
})
|
||||
.filter(({ videos }) => videos.length > 0)
|
||||
.reduce<VideoDefinitions>((accumulator, { id, videos, lastUpdated }) => {
|
||||
accumulator[id] = {
|
||||
videos,
|
||||
lastUpdated,
|
||||
};
|
||||
|
||||
return accumulator;
|
||||
}, {}),
|
||||
);
|
||||
@@ -2,5 +2,9 @@ import { lookup } from './lookup';
|
||||
|
||||
export async function encode(proto: string, data: any) {
|
||||
const Message = await lookup(proto);
|
||||
const verification = Message.verify(data);
|
||||
|
||||
if (verification !== null) throw new Error(verification);
|
||||
|
||||
return Message.encode(Message.create(data)).finish();
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { Root } from 'protobufjs';
|
||||
import { context } from '../blitzkit/context';
|
||||
|
||||
export async function lookup(proto: string) {
|
||||
const [file, message] = proto.split('/')[0];
|
||||
const [file, message] = proto.split('/');
|
||||
const root = await new Root().load(
|
||||
context === 'server'
|
||||
? `public/protos/${file}.proto`
|
||||
|
||||
Reference in new issue
Block a user