@dan-uni/dan-any 1.2.7 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/buf.gen.yaml +4 -2
- package/buf.yaml +12 -0
- package/dist/browser/17.min.js +24 -18
- package/dist/browser/src/index.d.ts +6 -5
- package/dist/browser/src/proto/gen/{bili → bilibili/community/service/dm/v1}/dm_pb.d.ts +2 -2
- package/dist/{umd/src/proto/gen/danuni_pb.d.ts → browser/src/proto/gen/danuni/danmaku/v1/danmaku_pb.d.ts} +45 -41
- package/dist/node/17.js +24 -18
- package/dist/node/src/index.d.ts +6 -5
- package/dist/{umd/src/proto/gen/bili → node/src/proto/gen/bilibili/community/service/dm/v1}/dm_pb.d.ts +2 -2
- package/dist/{browser/src/proto/gen/danuni_pb.d.ts → node/src/proto/gen/danuni/danmaku/v1/danmaku_pb.d.ts} +45 -41
- package/dist/umd/index.umd.min.js +95 -41
- package/dist/umd/plugins/bili.umd.min.js +91 -38
- package/dist/umd/plugins/index.umd.min.js +91 -38
- package/dist/umd/src/index.d.ts +6 -5
- package/dist/{node/src/proto/gen/bili → umd/src/proto/gen/bilibili/community/service/dm/v1}/dm_pb.d.ts +2 -2
- package/dist/{node/src/proto/gen/danuni_pb.d.ts → umd/src/proto/gen/danuni/danmaku/v1/danmaku_pb.d.ts} +45 -41
- package/package.json +2 -2
- package/src/index.test.ts +1 -1
- package/src/index.ts +23 -16
- package/src/proto/gen/{bili → bilibili/community/service/dm/v1}/dm_pb.ts +104 -104
- package/src/proto/gen/danuni/danmaku/v1/danmaku_pb.ts +223 -0
- package/src/proto/src/danuni/danmaku/v1/danmaku.proto +52 -0
- package/src/proto/gen/danuni_pb.ts +0 -219
- package/src/proto/src/danuni.proto +0 -50
- /package/src/proto/src/{bili → bilibili/community/service/dm/v1}/dm.proto +0 -0
package/src/index.test.ts
CHANGED
|
@@ -73,7 +73,7 @@ describe('转化自', () => {
|
|
|
73
73
|
const pb = pool.toPb()
|
|
74
74
|
console.info(UniPool.fromPb(pb))
|
|
75
75
|
const imp = UniPool.import(pb)
|
|
76
|
-
expect(imp.fmt).toBe('danuni.
|
|
76
|
+
expect(imp.fmt).toBe('danuni.binpb')
|
|
77
77
|
expect(imp.pool).toEqual(pool)
|
|
78
78
|
})
|
|
79
79
|
it('DDplay[双向]', () => {
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { isJSON, isObject, isString } from 'class-validator'
|
|
|
4
4
|
import { XMLBuilder, XMLParser } from 'fast-xml-parser'
|
|
5
5
|
import JSONbig from 'json-bigint'
|
|
6
6
|
import type { Options as AssGenOptions, CanvasCtx } from './ass-gen'
|
|
7
|
-
import type { CommandDm as DM_JSON_BiliCommandGrpc } from './proto/gen/
|
|
7
|
+
import type { CommandDm as DM_JSON_BiliCommandGrpc } from './proto/gen/bilibili/community/service/dm/v1/dm_pb'
|
|
8
|
+
import type { Danmaku } from './proto/gen/danuni/danmaku/v1/danmaku_pb'
|
|
8
9
|
|
|
9
10
|
import { create, fromBinary, toBinary } from '@bufbuild/protobuf'
|
|
10
11
|
import {
|
|
@@ -19,8 +20,8 @@ import {
|
|
|
19
20
|
// DanmakuElem as DM_JSON_BiliGrpc,
|
|
20
21
|
DmSegMobileReplySchema,
|
|
21
22
|
DmWebViewReplySchema,
|
|
22
|
-
} from './proto/gen/
|
|
23
|
-
import {
|
|
23
|
+
} from './proto/gen/bilibili/community/service/dm/v1/dm_pb'
|
|
24
|
+
import { ListDanResponseSchema } from './proto/gen/danuni/danmaku/v1/danmaku_pb'
|
|
24
25
|
// import type * as UniIDType from './utils/id-gen'
|
|
25
26
|
|
|
26
27
|
import { UniDM } from './utils/dm-gen'
|
|
@@ -153,10 +154,11 @@ export interface DM_JSON_DDPlay {
|
|
|
153
154
|
|
|
154
155
|
export enum DM_format {
|
|
155
156
|
DanuniJson = 'danuni.json',
|
|
156
|
-
|
|
157
|
+
DanuniMinJson = 'danuni.min.json',
|
|
158
|
+
DanuniPbBin = 'danuni.binpb',
|
|
157
159
|
BiliXml = 'bili.xml',
|
|
158
|
-
BiliPbBin = 'bili.
|
|
159
|
-
BiliCmdPbBin = 'bili.cmd.
|
|
160
|
+
BiliPbBin = 'bili.binpb',
|
|
161
|
+
BiliCmdPbBin = 'bili.cmd.binpb',
|
|
160
162
|
BiliUpJson = 'bili.up.json',
|
|
161
163
|
DplayerJson = 'dplayer.json',
|
|
162
164
|
ArtplayerJson = 'artplayer.json',
|
|
@@ -587,13 +589,15 @@ export class UniPool {
|
|
|
587
589
|
switch (format) {
|
|
588
590
|
case 'danuni.json':
|
|
589
591
|
return this.dans
|
|
590
|
-
case 'danuni.
|
|
592
|
+
case 'danuni.min.json':
|
|
593
|
+
return this.minify()
|
|
594
|
+
case 'danuni.binpb':
|
|
591
595
|
return this.toPb()
|
|
592
596
|
case 'bili.xml':
|
|
593
597
|
return this.toBiliXML()
|
|
594
|
-
// case 'bili.
|
|
598
|
+
// case 'bili.binpb':
|
|
595
599
|
// return this.toBiliBin()
|
|
596
|
-
// case 'bili.cmd.
|
|
600
|
+
// case 'bili.cmd.binpb':
|
|
597
601
|
// return this.toBiliCmdBin()
|
|
598
602
|
case 'dplayer.json':
|
|
599
603
|
return this.toDplayer()
|
|
@@ -611,14 +615,17 @@ export class UniPool {
|
|
|
611
615
|
}
|
|
612
616
|
}
|
|
613
617
|
static fromPb(bin: Uint8Array | ArrayBuffer, options?: Options) {
|
|
614
|
-
const data = fromBinary(
|
|
618
|
+
const data = fromBinary(ListDanResponseSchema, new Uint8Array(bin))
|
|
615
619
|
return new UniPool(
|
|
616
620
|
data.danmakus.map((d) =>
|
|
617
621
|
UniDM.create(
|
|
618
622
|
{
|
|
619
623
|
...d,
|
|
624
|
+
SOID: d.soid,
|
|
625
|
+
DMID: d.dmid,
|
|
620
626
|
progress: d.progress / 1000,
|
|
621
627
|
mode: d.mode as number,
|
|
628
|
+
senderID: d.senderId,
|
|
622
629
|
ctime: timestampDate(d.ctime || timestampNow()),
|
|
623
630
|
pool: d.pool as number,
|
|
624
631
|
attr: d.attr as UniDMTools.DMAttr[],
|
|
@@ -636,17 +643,17 @@ export class UniPool {
|
|
|
636
643
|
*/
|
|
637
644
|
toPb() {
|
|
638
645
|
return toBinary(
|
|
639
|
-
|
|
640
|
-
create(
|
|
646
|
+
ListDanResponseSchema,
|
|
647
|
+
create(ListDanResponseSchema, {
|
|
641
648
|
danmakus: this.dans.map((d) => {
|
|
642
649
|
return {
|
|
643
|
-
|
|
644
|
-
|
|
650
|
+
soid: d.SOID,
|
|
651
|
+
dmid: d.DMID ?? '',
|
|
645
652
|
progress: Math.round(d.progress * 1000),
|
|
646
653
|
mode: d.mode as number,
|
|
647
654
|
fontsize: d.fontsize,
|
|
648
655
|
color: d.color,
|
|
649
|
-
|
|
656
|
+
senderId: d.senderID,
|
|
650
657
|
content: d.content,
|
|
651
658
|
ctime: timestampFromDate(d.ctime),
|
|
652
659
|
weight: d.weight,
|
|
@@ -654,7 +661,7 @@ export class UniPool {
|
|
|
654
661
|
attr: d.attr,
|
|
655
662
|
platform: d.platform,
|
|
656
663
|
extra: d.extraStr,
|
|
657
|
-
}
|
|
664
|
+
} satisfies Omit<Danmaku, '$typeName'>
|
|
658
665
|
}),
|
|
659
666
|
}),
|
|
660
667
|
)
|