@dan-uni/dan-any 0.9.4 → 0.9.6

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.
@@ -160,6 +160,7 @@ interface DMBili {
160
160
  mode: number // xml 1
161
161
  fontsize: number // xml 2
162
162
  color: number // xml 3
163
+ mid?: number // 仅创作中心源
163
164
  midHash: string // xml 6
164
165
  /**
165
166
  * 特殊类型解析:
@@ -239,6 +240,8 @@ interface ExtraBili {
239
240
  mode?: number //原弹幕类型
240
241
  pool?: number //原弹幕池
241
242
  dmid?: bigint //原弹幕ID
243
+ attr?: number //原弹幕属性
244
+ mid?: number //发送者mid(仅创作中心源)
242
245
  adv?: string
243
246
  code?: string
244
247
  bas?: string
@@ -585,35 +588,36 @@ export class UniDM {
585
588
  type UObj = Partial<UniDMObj> & Pick<UniDMObj, 'SOID'>
586
589
  const def: UObj = UniDM.create()
587
590
  const dan: UObj = UniDM.create(this)
588
- // const prototypes = Object.getOwnPropertyNames(this)
589
- for (const key in dan) {
590
- const k = key as keyof UObj
591
- const v = dan[k]
592
- // if (key in prototypes) continue
593
- if (key === 'SOID') continue
594
- else if (!v) delete dan[k]
595
- else if (v === def[k]) delete dan[k]
596
- else {
597
- if (k === 'attr' && Array.isArray(v) && v.length === 0) delete dan[k]
598
- if (k === 'extraStr' && v === '{}') delete dan[k]
591
+ const shouldKeep = (key: keyof UObj, value: UObj[keyof UObj]) => {
592
+ if (key === 'SOID') return true
593
+ if (value === undefined || value === null) return false
594
+ if (value === def[key]) return false
595
+ if (key === 'attr' && Array.isArray(value) && value.length === 0)
596
+ return false
597
+ if (key === 'extraStr' && value === '{}') return false
598
+ return true
599
+ }
600
+ const result: UObj = { SOID: dan.SOID }
601
+ for (const key of Object.keys(dan) as (keyof UObj)[]) {
602
+ const value = dan[key]
603
+ if (shouldKeep(key, value)) {
604
+ if (key === 'SOID') continue
605
+ Reflect.set(result, key, value)
599
606
  }
600
607
  }
601
- return JSON.parse(JSON.stringify(dan)) as UObj
608
+ return result
602
609
  }
603
610
  @Expose()
604
- downgradeAdvcancedDan(
605
- {
606
- include,
607
- exclude,
608
- cleanExtra = false,
609
- }: {
610
- include?: (keyof Extra)[]
611
- exclude?: (keyof Extra)[]
612
- cleanExtra?: boolean
613
- } = { include: [], exclude: [] },
614
- ) {
615
- if (!this.extra) return this
616
- else {
611
+ downgradeAdvcancedDan({
612
+ include,
613
+ exclude,
614
+ cleanExtra = false,
615
+ }: {
616
+ include?: (keyof Extra)[]
617
+ exclude?: (keyof Extra)[]
618
+ cleanExtra?: boolean
619
+ } = {}) {
620
+ if (this.extra) {
617
621
  if (!include) include = []
618
622
  if (!exclude) exclude = []
619
623
  const check = (k: keyof Extra) =>
@@ -649,7 +653,7 @@ export class UniDM {
649
653
  clone.attr.push(DMAttr.Compatible)
650
654
  if (cleanExtra) clone.extraStr = undefined
651
655
  return clone
652
- }
656
+ } else return this
653
657
  }
654
658
  /**
655
659
  * 将各种类型的时间进行格式化
@@ -753,7 +757,13 @@ export class UniDM {
753
757
  let mode = Modes.Normal
754
758
  const pool = args.pool //暂时不做处理,兼容bili的pool格式
755
759
  const extra: TExtra = {
756
- bili: { mode: args.mode, pool: args.pool, dmid: args.id },
760
+ bili: {
761
+ mode: args.mode,
762
+ pool: args.pool,
763
+ dmid: args.id,
764
+ attr: args.attr,
765
+ mid: args.mid,
766
+ },
757
767
  }
758
768
  //重复 transMode ,但此处有关于extra的额外处理
759
769
  switch (args.mode) {
@@ -794,7 +804,7 @@ export class UniDM {
794
804
  senderID: senderID.toString(),
795
805
  // content: args.content,
796
806
  ctime: this.transCtime(args.ctime, 's'),
797
- weight: args.weight ? args.weight : pool === Pools.Ix ? 1 : 0,
807
+ weight: args.weight || (pool === Pools.Ix ? 1 : 0),
798
808
  pool,
799
809
  attr: DMAttrUtils.fromBin(args.attr, PlatformVideoSource.Bilibili),
800
810
  platform: PlatformVideoSource.Bilibili,
@@ -1 +1 @@
1
- {"version":"5.9.2"}
1
+ {"version":"5.9.3"}