bililive-cli 1.6.1 → 1.6.2

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.
@@ -4,7 +4,7 @@ var path$1 = require('node:path');
4
4
  var require$$0$b = require('node:http');
5
5
  var require$$0$a = require('node:url');
6
6
  require('node:https');
7
- var index = require('./index-C8BJBjBO.js');
7
+ var index = require('./index-CSU11uxG.cjs');
8
8
  var require$$0$4 = require('tty');
9
9
  var require$$1$1 = require('util');
10
10
  var require$$5$1 = require('assert');
@@ -238,859 +238,12 @@ function formatTime(time) {
238
238
  };
239
239
  }
240
240
 
241
- class XmlNode{
242
- constructor(tagname) {
243
- this.tagname = tagname;
244
- this.child = []; //nested tags, text, cdata, comments in order
245
- this[":@"] = {}; //attributes map
246
- }
247
- add(key,val){
248
- // this.child.push( {name : key, val: val, isCdata: isCdata });
249
- if(key === "__proto__") key = "#__proto__";
250
- this.child.push( {[key]: val });
251
- }
252
- addChild(node) {
253
- if(node.tagname === "__proto__") node.tagname = "#__proto__";
254
- if(node[":@"] && Object.keys(node[":@"]).length > 0){
255
- this.child.push( { [node.tagname]: node.child, [":@"]: node[":@"] });
256
- }else {
257
- this.child.push( { [node.tagname]: node.child });
258
- }
259
- };
260
- }
261
-
262
- var xmlNode$1 = XmlNode;
263
-
264
- const util$4 = index.util;
265
-
266
- //TODO: handle comments
267
- function readDocType$1(xmlData, i){
268
-
269
- const entities = {};
270
- if( xmlData[i + 3] === 'O' &&
271
- xmlData[i + 4] === 'C' &&
272
- xmlData[i + 5] === 'T' &&
273
- xmlData[i + 6] === 'Y' &&
274
- xmlData[i + 7] === 'P' &&
275
- xmlData[i + 8] === 'E')
276
- {
277
- i = i+9;
278
- let angleBracketsCount = 1;
279
- let hasBody = false, comment = false;
280
- let exp = "";
281
- for(;i<xmlData.length;i++){
282
- if (xmlData[i] === '<' && !comment) { //Determine the tag type
283
- if( hasBody && isEntity(xmlData, i)){
284
- i += 7;
285
- [entityName, val,i] = readEntityExp(xmlData,i+1);
286
- if(val.indexOf("&") === -1) //Parameter entities are not supported
287
- entities[ validateEntityName(entityName) ] = {
288
- regx : RegExp( `&${entityName};`,"g"),
289
- val: val
290
- };
291
- }
292
- else if( hasBody && isElement$1(xmlData, i)) i += 8;//Not supported
293
- else if( hasBody && isAttlist(xmlData, i)) i += 8;//Not supported
294
- else if( hasBody && isNotation(xmlData, i)) i += 9;//Not supported
295
- else if( isComment) comment = true;
296
- else throw new Error("Invalid DOCTYPE");
297
-
298
- angleBracketsCount++;
299
- exp = "";
300
- } else if (xmlData[i] === '>') { //Read tag content
301
- if(comment){
302
- if( xmlData[i - 1] === "-" && xmlData[i - 2] === "-"){
303
- comment = false;
304
- angleBracketsCount--;
305
- }
306
- }else {
307
- angleBracketsCount--;
308
- }
309
- if (angleBracketsCount === 0) {
310
- break;
311
- }
312
- }else if( xmlData[i] === '['){
313
- hasBody = true;
314
- }else {
315
- exp += xmlData[i];
316
- }
317
- }
318
- if(angleBracketsCount !== 0){
319
- throw new Error(`Unclosed DOCTYPE`);
320
- }
321
- }else {
322
- throw new Error(`Invalid Tag instead of DOCTYPE`);
323
- }
324
- return {entities, i};
325
- }
326
-
327
- function readEntityExp(xmlData,i){
328
- //External entities are not supported
329
- // <!ENTITY ext SYSTEM "http://normal-website.com" >
330
-
331
- //Parameter entities are not supported
332
- // <!ENTITY entityname "&anotherElement;">
333
-
334
- //Internal entities are supported
335
- // <!ENTITY entityname "replacement text">
336
-
337
- //read EntityName
338
- let entityName = "";
339
- for (; i < xmlData.length && (xmlData[i] !== "'" && xmlData[i] !== '"' ); i++) {
340
- // if(xmlData[i] === " ") continue;
341
- // else
342
- entityName += xmlData[i];
343
- }
344
- entityName = entityName.trim();
345
- if(entityName.indexOf(" ") !== -1) throw new Error("External entites are not supported");
346
-
347
- //read Entity Value
348
- const startChar = xmlData[i++];
349
- let val = "";
350
- for (; i < xmlData.length && xmlData[i] !== startChar ; i++) {
351
- val += xmlData[i];
352
- }
353
- return [entityName, val, i];
354
- }
355
-
356
- function isComment(xmlData, i){
357
- if(xmlData[i+1] === '!' &&
358
- xmlData[i+2] === '-' &&
359
- xmlData[i+3] === '-') return true
360
- return false
361
- }
362
- function isEntity(xmlData, i){
363
- if(xmlData[i+1] === '!' &&
364
- xmlData[i+2] === 'E' &&
365
- xmlData[i+3] === 'N' &&
366
- xmlData[i+4] === 'T' &&
367
- xmlData[i+5] === 'I' &&
368
- xmlData[i+6] === 'T' &&
369
- xmlData[i+7] === 'Y') return true
370
- return false
371
- }
372
- function isElement$1(xmlData, i){
373
- if(xmlData[i+1] === '!' &&
374
- xmlData[i+2] === 'E' &&
375
- xmlData[i+3] === 'L' &&
376
- xmlData[i+4] === 'E' &&
377
- xmlData[i+5] === 'M' &&
378
- xmlData[i+6] === 'E' &&
379
- xmlData[i+7] === 'N' &&
380
- xmlData[i+8] === 'T') return true
381
- return false
382
- }
383
-
384
- function isAttlist(xmlData, i){
385
- if(xmlData[i+1] === '!' &&
386
- xmlData[i+2] === 'A' &&
387
- xmlData[i+3] === 'T' &&
388
- xmlData[i+4] === 'T' &&
389
- xmlData[i+5] === 'L' &&
390
- xmlData[i+6] === 'I' &&
391
- xmlData[i+7] === 'S' &&
392
- xmlData[i+8] === 'T') return true
393
- return false
394
- }
395
- function isNotation(xmlData, i){
396
- if(xmlData[i+1] === '!' &&
397
- xmlData[i+2] === 'N' &&
398
- xmlData[i+3] === 'O' &&
399
- xmlData[i+4] === 'T' &&
400
- xmlData[i+5] === 'A' &&
401
- xmlData[i+6] === 'T' &&
402
- xmlData[i+7] === 'I' &&
403
- xmlData[i+8] === 'O' &&
404
- xmlData[i+9] === 'N') return true
405
- return false
406
- }
407
-
408
- function validateEntityName(name){
409
- if (util$4.isName(name))
410
- return name;
411
- else
412
- throw new Error(`Invalid entity name ${name}`);
413
- }
414
-
415
- var DocTypeReader = readDocType$1;
416
-
417
- ///@ts-check
418
-
419
- const util$3 = index.util;
420
- const xmlNode = xmlNode$1;
421
- const readDocType = DocTypeReader;
422
- const toNumber = index.strnum;
423
- const getIgnoreAttributesFn = index.ignoreAttributes;
424
-
425
- // const regx =
426
- // '<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)'
427
- // .replace(/NAME/g, util.nameRegexp);
428
-
429
- //const tagsRegx = new RegExp("<(\\/?[\\w:\\-\._]+)([^>]*)>(\\s*"+cdataRegx+")*([^<]+)?","g");
430
- //const tagsRegx = new RegExp("<(\\/?)((\\w*:)?([\\w:\\-\._]+))([^>]*)>([^<]*)("+cdataRegx+"([^<]*))*([^<]+)?","g");
431
-
432
- let OrderedObjParser$1 = class OrderedObjParser{
433
- constructor(options){
434
- this.options = options;
435
- this.currentNode = null;
436
- this.tagsNodeStack = [];
437
- this.docTypeEntities = {};
438
- this.lastEntities = {
439
- "apos" : { regex: /&(apos|#39|#x27);/g, val : "'"},
440
- "gt" : { regex: /&(gt|#62|#x3E);/g, val : ">"},
441
- "lt" : { regex: /&(lt|#60|#x3C);/g, val : "<"},
442
- "quot" : { regex: /&(quot|#34|#x22);/g, val : "\""},
443
- };
444
- this.ampEntity = { regex: /&(amp|#38|#x26);/g, val : "&"};
445
- this.htmlEntities = {
446
- "space": { regex: /&(nbsp|#160);/g, val: " " },
447
- // "lt" : { regex: /&(lt|#60);/g, val: "<" },
448
- // "gt" : { regex: /&(gt|#62);/g, val: ">" },
449
- // "amp" : { regex: /&(amp|#38);/g, val: "&" },
450
- // "quot" : { regex: /&(quot|#34);/g, val: "\"" },
451
- // "apos" : { regex: /&(apos|#39);/g, val: "'" },
452
- "cent" : { regex: /&(cent|#162);/g, val: "¢" },
453
- "pound" : { regex: /&(pound|#163);/g, val: "£" },
454
- "yen" : { regex: /&(yen|#165);/g, val: "¥" },
455
- "euro" : { regex: /&(euro|#8364);/g, val: "€" },
456
- "copyright" : { regex: /&(copy|#169);/g, val: "©" },
457
- "reg" : { regex: /&(reg|#174);/g, val: "®" },
458
- "inr" : { regex: /&(inr|#8377);/g, val: "₹" },
459
- "num_dec": { regex: /&#([0-9]{1,7});/g, val : (_, str) => String.fromCharCode(Number.parseInt(str, 10)) },
460
- "num_hex": { regex: /&#x([0-9a-fA-F]{1,6});/g, val : (_, str) => String.fromCharCode(Number.parseInt(str, 16)) },
461
- };
462
- this.addExternalEntities = addExternalEntities;
463
- this.parseXml = parseXml;
464
- this.parseTextData = parseTextData;
465
- this.resolveNameSpace = resolveNameSpace;
466
- this.buildAttributesMap = buildAttributesMap;
467
- this.isItStopNode = isItStopNode;
468
- this.replaceEntitiesValue = replaceEntitiesValue;
469
- this.readStopNodeData = readStopNodeData;
470
- this.saveTextToParentTag = saveTextToParentTag;
471
- this.addChild = addChild;
472
- this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes);
473
- }
474
-
475
- };
476
-
477
- function addExternalEntities(externalEntities){
478
- const entKeys = Object.keys(externalEntities);
479
- for (let i = 0; i < entKeys.length; i++) {
480
- const ent = entKeys[i];
481
- this.lastEntities[ent] = {
482
- regex: new RegExp("&"+ent+";","g"),
483
- val : externalEntities[ent]
484
- };
485
- }
486
- }
487
-
488
- /**
489
- * @param {string} val
490
- * @param {string} tagName
491
- * @param {string} jPath
492
- * @param {boolean} dontTrim
493
- * @param {boolean} hasAttributes
494
- * @param {boolean} isLeafNode
495
- * @param {boolean} escapeEntities
496
- */
497
- function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
498
- if (val !== undefined) {
499
- if (this.options.trimValues && !dontTrim) {
500
- val = val.trim();
501
- }
502
- if(val.length > 0){
503
- if(!escapeEntities) val = this.replaceEntitiesValue(val);
504
-
505
- const newval = this.options.tagValueProcessor(tagName, val, jPath, hasAttributes, isLeafNode);
506
- if(newval === null || newval === undefined){
507
- //don't parse
508
- return val;
509
- }else if(typeof newval !== typeof val || newval !== val){
510
- //overwrite
511
- return newval;
512
- }else if(this.options.trimValues){
513
- return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
514
- }else {
515
- const trimmedVal = val.trim();
516
- if(trimmedVal === val){
517
- return parseValue(val, this.options.parseTagValue, this.options.numberParseOptions);
518
- }else {
519
- return val;
520
- }
521
- }
522
- }
523
- }
524
- }
525
-
526
- function resolveNameSpace(tagname) {
527
- if (this.options.removeNSPrefix) {
528
- const tags = tagname.split(':');
529
- const prefix = tagname.charAt(0) === '/' ? '/' : '';
530
- if (tags[0] === 'xmlns') {
531
- return '';
532
- }
533
- if (tags.length === 2) {
534
- tagname = prefix + tags[1];
535
- }
536
- }
537
- return tagname;
538
- }
539
-
540
- //TODO: change regex to capture NS
541
- //const attrsRegx = new RegExp("([\\w\\-\\.\\:]+)\\s*=\\s*(['\"])((.|\n)*?)\\2","gm");
542
- const attrsRegx = new RegExp('([^\\s=]+)\\s*(=\\s*([\'"])([\\s\\S]*?)\\3)?', 'gm');
543
-
544
- function buildAttributesMap(attrStr, jPath, tagName) {
545
- if (this.options.ignoreAttributes !== true && typeof attrStr === 'string') {
546
- // attrStr = attrStr.replace(/\r?\n/g, ' ');
547
- //attrStr = attrStr || attrStr.trim();
548
-
549
- const matches = util$3.getAllMatches(attrStr, attrsRegx);
550
- const len = matches.length; //don't make it inline
551
- const attrs = {};
552
- for (let i = 0; i < len; i++) {
553
- const attrName = this.resolveNameSpace(matches[i][1]);
554
- if (this.ignoreAttributesFn(attrName, jPath)) {
555
- continue
556
- }
557
- let oldVal = matches[i][4];
558
- let aName = this.options.attributeNamePrefix + attrName;
559
- if (attrName.length) {
560
- if (this.options.transformAttributeName) {
561
- aName = this.options.transformAttributeName(aName);
562
- }
563
- if(aName === "__proto__") aName = "#__proto__";
564
- if (oldVal !== undefined) {
565
- if (this.options.trimValues) {
566
- oldVal = oldVal.trim();
567
- }
568
- oldVal = this.replaceEntitiesValue(oldVal);
569
- const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPath);
570
- if(newVal === null || newVal === undefined){
571
- //don't parse
572
- attrs[aName] = oldVal;
573
- }else if(typeof newVal !== typeof oldVal || newVal !== oldVal){
574
- //overwrite
575
- attrs[aName] = newVal;
576
- }else {
577
- //parse
578
- attrs[aName] = parseValue(
579
- oldVal,
580
- this.options.parseAttributeValue,
581
- this.options.numberParseOptions
582
- );
583
- }
584
- } else if (this.options.allowBooleanAttributes) {
585
- attrs[aName] = true;
586
- }
587
- }
588
- }
589
- if (!Object.keys(attrs).length) {
590
- return;
591
- }
592
- if (this.options.attributesGroupName) {
593
- const attrCollection = {};
594
- attrCollection[this.options.attributesGroupName] = attrs;
595
- return attrCollection;
596
- }
597
- return attrs
598
- }
599
- }
600
-
601
- const parseXml = function(xmlData) {
602
- xmlData = xmlData.replace(/\r\n?/g, "\n"); //TODO: remove this line
603
- const xmlObj = new xmlNode('!xml');
604
- let currentNode = xmlObj;
605
- let textData = "";
606
- let jPath = "";
607
- for(let i=0; i< xmlData.length; i++){//for each char in XML data
608
- const ch = xmlData[i];
609
- if(ch === '<'){
610
- // const nextIndex = i+1;
611
- // const _2ndChar = xmlData[nextIndex];
612
- if( xmlData[i+1] === '/') {//Closing Tag
613
- const closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed.");
614
- let tagName = xmlData.substring(i+2,closeIndex).trim();
615
-
616
- if(this.options.removeNSPrefix){
617
- const colonIndex = tagName.indexOf(":");
618
- if(colonIndex !== -1){
619
- tagName = tagName.substr(colonIndex+1);
620
- }
621
- }
622
-
623
- if(this.options.transformTagName) {
624
- tagName = this.options.transformTagName(tagName);
625
- }
626
-
627
- if(currentNode){
628
- textData = this.saveTextToParentTag(textData, currentNode, jPath);
629
- }
630
-
631
- //check if last tag of nested tag was unpaired tag
632
- const lastTagName = jPath.substring(jPath.lastIndexOf(".")+1);
633
- if(tagName && this.options.unpairedTags.indexOf(tagName) !== -1 ){
634
- throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
635
- }
636
- let propIndex = 0;
637
- if(lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1 ){
638
- propIndex = jPath.lastIndexOf('.', jPath.lastIndexOf('.')-1);
639
- this.tagsNodeStack.pop();
640
- }else {
641
- propIndex = jPath.lastIndexOf(".");
642
- }
643
- jPath = jPath.substring(0, propIndex);
644
-
645
- currentNode = this.tagsNodeStack.pop();//avoid recursion, set the parent tag scope
646
- textData = "";
647
- i = closeIndex;
648
- } else if( xmlData[i+1] === '?') {
649
-
650
- let tagData = readTagExp(xmlData,i, false, "?>");
651
- if(!tagData) throw new Error("Pi Tag is not closed.");
652
-
653
- textData = this.saveTextToParentTag(textData, currentNode, jPath);
654
- if( (this.options.ignoreDeclaration && tagData.tagName === "?xml") || this.options.ignorePiTags);else {
655
-
656
- const childNode = new xmlNode(tagData.tagName);
657
- childNode.add(this.options.textNodeName, "");
658
-
659
- if(tagData.tagName !== tagData.tagExp && tagData.attrExpPresent){
660
- childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath, tagData.tagName);
661
- }
662
- this.addChild(currentNode, childNode, jPath);
663
-
664
- }
665
-
666
-
667
- i = tagData.closeIndex + 1;
668
- } else if(xmlData.substr(i + 1, 3) === '!--') {
669
- const endIndex = findClosingIndex(xmlData, "-->", i+4, "Comment is not closed.");
670
- if(this.options.commentPropName){
671
- const comment = xmlData.substring(i + 4, endIndex - 2);
672
-
673
- textData = this.saveTextToParentTag(textData, currentNode, jPath);
674
-
675
- currentNode.add(this.options.commentPropName, [ { [this.options.textNodeName] : comment } ]);
676
- }
677
- i = endIndex;
678
- } else if( xmlData.substr(i + 1, 2) === '!D') {
679
- const result = readDocType(xmlData, i);
680
- this.docTypeEntities = result.entities;
681
- i = result.i;
682
- }else if(xmlData.substr(i + 1, 2) === '![') {
683
- const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
684
- const tagExp = xmlData.substring(i + 9,closeIndex);
685
-
686
- textData = this.saveTextToParentTag(textData, currentNode, jPath);
687
-
688
- let val = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true, true);
689
- if(val == undefined) val = "";
690
-
691
- //cdata should be set even if it is 0 length string
692
- if(this.options.cdataPropName){
693
- currentNode.add(this.options.cdataPropName, [ { [this.options.textNodeName] : tagExp } ]);
694
- }else {
695
- currentNode.add(this.options.textNodeName, val);
696
- }
697
-
698
- i = closeIndex + 2;
699
- }else {//Opening tag
700
- let result = readTagExp(xmlData,i, this.options.removeNSPrefix);
701
- let tagName= result.tagName;
702
- const rawTagName = result.rawTagName;
703
- let tagExp = result.tagExp;
704
- let attrExpPresent = result.attrExpPresent;
705
- let closeIndex = result.closeIndex;
706
-
707
- if (this.options.transformTagName) {
708
- tagName = this.options.transformTagName(tagName);
709
- }
710
-
711
- //save text as child node
712
- if (currentNode && textData) {
713
- if(currentNode.tagname !== '!xml'){
714
- //when nested tag is found
715
- textData = this.saveTextToParentTag(textData, currentNode, jPath, false);
716
- }
717
- }
718
-
719
- //check if last tag was unpaired tag
720
- const lastTag = currentNode;
721
- if(lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1 ){
722
- currentNode = this.tagsNodeStack.pop();
723
- jPath = jPath.substring(0, jPath.lastIndexOf("."));
724
- }
725
- if(tagName !== xmlObj.tagname){
726
- jPath += jPath ? "." + tagName : tagName;
727
- }
728
- if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) {
729
- let tagContent = "";
730
- //self-closing tag
731
- if(tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1){
732
- if(tagName[tagName.length - 1] === "/"){ //remove trailing '/'
733
- tagName = tagName.substr(0, tagName.length - 1);
734
- jPath = jPath.substr(0, jPath.length - 1);
735
- tagExp = tagName;
736
- }else {
737
- tagExp = tagExp.substr(0, tagExp.length - 1);
738
- }
739
- i = result.closeIndex;
740
- }
741
- //unpaired tag
742
- else if(this.options.unpairedTags.indexOf(tagName) !== -1){
743
-
744
- i = result.closeIndex;
745
- }
746
- //normal tag
747
- else {
748
- //read until closing tag is found
749
- const result = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);
750
- if(!result) throw new Error(`Unexpected end of ${rawTagName}`);
751
- i = result.i;
752
- tagContent = result.tagContent;
753
- }
754
-
755
- const childNode = new xmlNode(tagName);
756
- if(tagName !== tagExp && attrExpPresent){
757
- childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
758
- }
759
- if(tagContent) {
760
- tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
761
- }
762
-
763
- jPath = jPath.substr(0, jPath.lastIndexOf("."));
764
- childNode.add(this.options.textNodeName, tagContent);
765
-
766
- this.addChild(currentNode, childNode, jPath);
767
- }else {
768
- //selfClosing tag
769
- if(tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1){
770
- if(tagName[tagName.length - 1] === "/"){ //remove trailing '/'
771
- tagName = tagName.substr(0, tagName.length - 1);
772
- jPath = jPath.substr(0, jPath.length - 1);
773
- tagExp = tagName;
774
- }else {
775
- tagExp = tagExp.substr(0, tagExp.length - 1);
776
- }
777
-
778
- if(this.options.transformTagName) {
779
- tagName = this.options.transformTagName(tagName);
780
- }
781
-
782
- const childNode = new xmlNode(tagName);
783
- if(tagName !== tagExp && attrExpPresent){
784
- childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
785
- }
786
- this.addChild(currentNode, childNode, jPath);
787
- jPath = jPath.substr(0, jPath.lastIndexOf("."));
788
- }
789
- //opening tag
790
- else {
791
- const childNode = new xmlNode( tagName);
792
- this.tagsNodeStack.push(currentNode);
793
-
794
- if(tagName !== tagExp && attrExpPresent){
795
- childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
796
- }
797
- this.addChild(currentNode, childNode, jPath);
798
- currentNode = childNode;
799
- }
800
- textData = "";
801
- i = closeIndex;
802
- }
803
- }
804
- }else {
805
- textData += xmlData[i];
806
- }
807
- }
808
- return xmlObj.child;
809
- };
810
-
811
- function addChild(currentNode, childNode, jPath){
812
- const result = this.options.updateTag(childNode.tagname, jPath, childNode[":@"]);
813
- if(result === false);else if(typeof result === "string"){
814
- childNode.tagname = result;
815
- currentNode.addChild(childNode);
816
- }else {
817
- currentNode.addChild(childNode);
818
- }
819
- }
820
-
821
- const replaceEntitiesValue = function(val){
822
-
823
- if(this.options.processEntities){
824
- for(let entityName in this.docTypeEntities){
825
- const entity = this.docTypeEntities[entityName];
826
- val = val.replace( entity.regx, entity.val);
827
- }
828
- for(let entityName in this.lastEntities){
829
- const entity = this.lastEntities[entityName];
830
- val = val.replace( entity.regex, entity.val);
831
- }
832
- if(this.options.htmlEntities){
833
- for(let entityName in this.htmlEntities){
834
- const entity = this.htmlEntities[entityName];
835
- val = val.replace( entity.regex, entity.val);
836
- }
837
- }
838
- val = val.replace( this.ampEntity.regex, this.ampEntity.val);
839
- }
840
- return val;
841
- };
842
- function saveTextToParentTag(textData, currentNode, jPath, isLeafNode) {
843
- if (textData) { //store previously collected data as textNode
844
- if(isLeafNode === undefined) isLeafNode = Object.keys(currentNode.child).length === 0;
845
-
846
- textData = this.parseTextData(textData,
847
- currentNode.tagname,
848
- jPath,
849
- false,
850
- currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false,
851
- isLeafNode);
852
-
853
- if (textData !== undefined && textData !== "")
854
- currentNode.add(this.options.textNodeName, textData);
855
- textData = "";
856
- }
857
- return textData;
858
- }
859
-
860
- //TODO: use jPath to simplify the logic
861
- /**
862
- *
863
- * @param {string[]} stopNodes
864
- * @param {string} jPath
865
- * @param {string} currentTagName
866
- */
867
- function isItStopNode(stopNodes, jPath, currentTagName){
868
- const allNodesExp = "*." + currentTagName;
869
- for (const stopNodePath in stopNodes) {
870
- const stopNodeExp = stopNodes[stopNodePath];
871
- if( allNodesExp === stopNodeExp || jPath === stopNodeExp ) return true;
872
- }
873
- return false;
874
- }
875
-
876
- /**
877
- * Returns the tag Expression and where it is ending handling single-double quotes situation
878
- * @param {string} xmlData
879
- * @param {number} i starting index
880
- * @returns
881
- */
882
- function tagExpWithClosingIndex(xmlData, i, closingChar = ">"){
883
- let attrBoundary;
884
- let tagExp = "";
885
- for (let index = i; index < xmlData.length; index++) {
886
- let ch = xmlData[index];
887
- if (attrBoundary) {
888
- if (ch === attrBoundary) attrBoundary = "";//reset
889
- } else if (ch === '"' || ch === "'") {
890
- attrBoundary = ch;
891
- } else if (ch === closingChar[0]) {
892
- if(closingChar[1]){
893
- if(xmlData[index + 1] === closingChar[1]){
894
- return {
895
- data: tagExp,
896
- index: index
897
- }
898
- }
899
- }else {
900
- return {
901
- data: tagExp,
902
- index: index
903
- }
904
- }
905
- } else if (ch === '\t') {
906
- ch = " ";
907
- }
908
- tagExp += ch;
909
- }
910
- }
911
-
912
- function findClosingIndex(xmlData, str, i, errMsg){
913
- const closingIndex = xmlData.indexOf(str, i);
914
- if(closingIndex === -1){
915
- throw new Error(errMsg)
916
- }else {
917
- return closingIndex + str.length - 1;
918
- }
919
- }
920
-
921
- function readTagExp(xmlData,i, removeNSPrefix, closingChar = ">"){
922
- const result = tagExpWithClosingIndex(xmlData, i+1, closingChar);
923
- if(!result) return;
924
- let tagExp = result.data;
925
- const closeIndex = result.index;
926
- const separatorIndex = tagExp.search(/\s/);
927
- let tagName = tagExp;
928
- let attrExpPresent = true;
929
- if(separatorIndex !== -1){//separate tag name and attributes expression
930
- tagName = tagExp.substring(0, separatorIndex);
931
- tagExp = tagExp.substring(separatorIndex + 1).trimStart();
932
- }
933
-
934
- const rawTagName = tagName;
935
- if(removeNSPrefix){
936
- const colonIndex = tagName.indexOf(":");
937
- if(colonIndex !== -1){
938
- tagName = tagName.substr(colonIndex+1);
939
- attrExpPresent = tagName !== result.data.substr(colonIndex + 1);
940
- }
941
- }
942
-
943
- return {
944
- tagName: tagName,
945
- tagExp: tagExp,
946
- closeIndex: closeIndex,
947
- attrExpPresent: attrExpPresent,
948
- rawTagName: rawTagName,
949
- }
950
- }
951
- /**
952
- * find paired tag for a stop node
953
- * @param {string} xmlData
954
- * @param {string} tagName
955
- * @param {number} i
956
- */
957
- function readStopNodeData(xmlData, tagName, i){
958
- const startIndex = i;
959
- // Starting at 1 since we already have an open tag
960
- let openTagCount = 1;
961
-
962
- for (; i < xmlData.length; i++) {
963
- if( xmlData[i] === "<"){
964
- if (xmlData[i+1] === "/") {//close tag
965
- const closeIndex = findClosingIndex(xmlData, ">", i, `${tagName} is not closed`);
966
- let closeTagName = xmlData.substring(i+2,closeIndex).trim();
967
- if(closeTagName === tagName){
968
- openTagCount--;
969
- if (openTagCount === 0) {
970
- return {
971
- tagContent: xmlData.substring(startIndex, i),
972
- i : closeIndex
973
- }
974
- }
975
- }
976
- i=closeIndex;
977
- } else if(xmlData[i+1] === '?') {
978
- const closeIndex = findClosingIndex(xmlData, "?>", i+1, "StopNode is not closed.");
979
- i=closeIndex;
980
- } else if(xmlData.substr(i + 1, 3) === '!--') {
981
- const closeIndex = findClosingIndex(xmlData, "-->", i+3, "StopNode is not closed.");
982
- i=closeIndex;
983
- } else if(xmlData.substr(i + 1, 2) === '![') {
984
- const closeIndex = findClosingIndex(xmlData, "]]>", i, "StopNode is not closed.") - 2;
985
- i=closeIndex;
986
- } else {
987
- const tagData = readTagExp(xmlData, i, '>');
988
-
989
- if (tagData) {
990
- const openTagName = tagData && tagData.tagName;
991
- if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length-1] !== "/") {
992
- openTagCount++;
993
- }
994
- i=tagData.closeIndex;
995
- }
996
- }
997
- }
998
- }//end for loop
999
- }
1000
-
1001
- function parseValue(val, shouldParse, options) {
1002
- if (shouldParse && typeof val === 'string') {
1003
- //console.log(options)
1004
- const newval = val.trim();
1005
- if(newval === 'true' ) return true;
1006
- else if(newval === 'false' ) return false;
1007
- else return toNumber(val, options);
1008
- } else {
1009
- if (util$3.isExist(val)) {
1010
- return val;
1011
- } else {
1012
- return '';
1013
- }
1014
- }
1015
- }
1016
-
1017
-
1018
- var OrderedObjParser_1 = OrderedObjParser$1;
1019
-
1020
- const { buildOptions} = index.OptionsBuilder;
1021
- const OrderedObjParser = OrderedObjParser_1;
1022
- const { prettify} = index.node2json;
1023
- const validator$1 = index.validator;
1024
-
1025
- let XMLParser$1 = class XMLParser{
1026
-
1027
- constructor(options){
1028
- this.externalEntities = {};
1029
- this.options = buildOptions(options);
1030
-
1031
- }
1032
- /**
1033
- * Parse XML dats to JS object
1034
- * @param {string|Buffer} xmlData
1035
- * @param {boolean|Object} validationOption
1036
- */
1037
- parse(xmlData,validationOption){
1038
- if(typeof xmlData === "string");else if( xmlData.toString){
1039
- xmlData = xmlData.toString();
1040
- }else {
1041
- throw new Error("XML data is accepted in String or Bytes[] form.")
1042
- }
1043
- if( validationOption){
1044
- if(validationOption === true) validationOption = {}; //validate with default options
1045
-
1046
- const result = validator$1.validate(xmlData, validationOption);
1047
- if (result !== true) {
1048
- throw Error( `${result.err.msg}:${result.err.line}:${result.err.col}` )
1049
- }
1050
- }
1051
- const orderedObjParser = new OrderedObjParser(this.options);
1052
- orderedObjParser.addExternalEntities(this.externalEntities);
1053
- const orderedResult = orderedObjParser.parseXml(xmlData);
1054
- if(this.options.preserveOrder || orderedResult === undefined) return orderedResult;
1055
- else return prettify(orderedResult, this.options);
1056
- }
1057
-
1058
- /**
1059
- * Add Entity which is not by default supported by this library
1060
- * @param {string} key
1061
- * @param {string} value
1062
- */
1063
- addEntity(key, value){
1064
- if(value.indexOf("&") !== -1){
1065
- throw new Error("Entity value can't have '&'")
1066
- }else if(key.indexOf("&") !== -1 || key.indexOf(";") !== -1){
1067
- throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '&#xD;'")
1068
- }else if(value === "&"){
1069
- throw new Error("An entity with value '&' is not permitted");
1070
- }else {
1071
- this.externalEntities[key] = value;
1072
- }
1073
- }
1074
- };
1075
-
1076
- var XMLParser_1 = XMLParser$1;
1077
-
1078
- const validator = index.validator;
1079
- const XMLParser = XMLParser_1;
1080
- const XMLBuilder = index.json2xml;
1081
-
1082
- var fxp = {
1083
- XMLParser: XMLParser,
1084
- XMLValidator: validator,
1085
- XMLBuilder: XMLBuilder
1086
- };
1087
-
1088
241
  /**
1089
242
  * 转换弹幕为b站格式xml
1090
243
  * @link: https://socialsisteryi.github.io/bilibili-API-collect/docs/danmaku/danmaku_xml.html#%E5%B1%9E%E6%80%A7-p
1091
244
  */
1092
245
  function convert2Xml(data, metadata) {
1093
- const builder = new fxp.XMLBuilder({
246
+ const builder = new index.fxp.XMLBuilder({
1094
247
  ignoreAttributes: false,
1095
248
  attributeNamePrefix: "@@",
1096
249
  format: true,
@@ -5227,51 +4380,60 @@ function encodeUrl (url) {
5227
4380
 
5228
4381
  var responseExports = response$1.exports;
5229
4382
 
5230
- /**
5231
- * Expose compositor.
5232
- */
4383
+ var koaCompose;
4384
+ var hasRequiredKoaCompose;
5233
4385
 
5234
- var koaCompose = compose$3;
4386
+ function requireKoaCompose () {
4387
+ if (hasRequiredKoaCompose) return koaCompose;
4388
+ hasRequiredKoaCompose = 1;
5235
4389
 
5236
- /**
5237
- * Compose `middleware` returning
5238
- * a fully valid middleware comprised
5239
- * of all those which are passed.
5240
- *
5241
- * @param {Array} middleware
5242
- * @return {Function}
5243
- * @api public
5244
- */
4390
+ /**
4391
+ * Expose compositor.
4392
+ */
5245
4393
 
5246
- function compose$3 (middleware) {
5247
- if (!Array.isArray(middleware)) throw new TypeError('Middleware stack must be an array!')
5248
- for (const fn of middleware) {
5249
- if (typeof fn !== 'function') throw new TypeError('Middleware must be composed of functions!')
5250
- }
4394
+ koaCompose = compose;
5251
4395
 
5252
- /**
5253
- * @param {Object} context
5254
- * @return {Promise}
5255
- * @api public
5256
- */
4396
+ /**
4397
+ * Compose `middleware` returning
4398
+ * a fully valid middleware comprised
4399
+ * of all those which are passed.
4400
+ *
4401
+ * @param {Array} middleware
4402
+ * @return {Function}
4403
+ * @api public
4404
+ */
5257
4405
 
5258
- return function (context, next) {
5259
- // last called middleware #
5260
- let index = -1;
5261
- return dispatch(0)
5262
- function dispatch (i) {
5263
- if (i <= index) return Promise.reject(new Error('next() called multiple times'))
5264
- index = i;
5265
- let fn = middleware[i];
5266
- if (i === middleware.length) fn = next;
5267
- if (!fn) return Promise.resolve()
5268
- try {
5269
- return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
5270
- } catch (err) {
5271
- return Promise.reject(err)
5272
- }
5273
- }
5274
- }
4406
+ function compose (middleware) {
4407
+ if (!Array.isArray(middleware)) throw new TypeError('Middleware stack must be an array!')
4408
+ for (const fn of middleware) {
4409
+ if (typeof fn !== 'function') throw new TypeError('Middleware must be composed of functions!')
4410
+ }
4411
+
4412
+ /**
4413
+ * @param {Object} context
4414
+ * @return {Promise}
4415
+ * @api public
4416
+ */
4417
+
4418
+ return function (context, next) {
4419
+ // last called middleware #
4420
+ let index = -1;
4421
+ return dispatch(0)
4422
+ function dispatch (i) {
4423
+ if (i <= index) return Promise.reject(new Error('next() called multiple times'))
4424
+ index = i;
4425
+ let fn = middleware[i];
4426
+ if (i === middleware.length) fn = next;
4427
+ if (!fn) return Promise.resolve()
4428
+ try {
4429
+ return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
4430
+ } catch (err) {
4431
+ return Promise.reject(err)
4432
+ }
4433
+ }
4434
+ }
4435
+ }
4436
+ return koaCompose;
5275
4437
  }
5276
4438
 
5277
4439
  var context$1 = {exports: {}};
@@ -11554,7 +10716,7 @@ function isObject(val) {
11554
10716
  */
11555
10717
 
11556
10718
  const co = co_1;
11557
- const compose$2 = koaCompose;
10719
+ const compose$2 = requireKoaCompose();
11558
10720
 
11559
10721
  /**
11560
10722
  * Expose `convert()`.
@@ -11662,7 +10824,7 @@ const debug$1 = srcExports('koa:application');
11662
10824
  const onFinished = onFinishedExports;
11663
10825
  const assert = require$$5$1;
11664
10826
  const response = responseExports;
11665
- const compose$1 = koaCompose;
10827
+ const compose$1 = requireKoaCompose();
11666
10828
  const context = contextExports;
11667
10829
  const request = requestExports;
11668
10830
  const statuses$1 = statuses$2;
@@ -13199,7 +12361,7 @@ const util$1 = require$$1$4;
13199
12361
 
13200
12362
  const debug = util$1.debuglog('koa-router');
13201
12363
 
13202
- const compose = koaCompose;
12364
+ const compose = requireKoaCompose();
13203
12365
  const HttpError = requireHttpErrors();
13204
12366
  const { pathToRegexp } = requireDist();
13205
12367
 
@@ -45239,7 +44401,7 @@ const parseXmlFile = async (input, parseRaw = false) => {
45239
44401
  * 解析弹幕数据为对象
45240
44402
  */
45241
44403
  const parseXmlObj = async (XMLdata) => {
45242
- const parser = new fxp.XMLParser({
44404
+ const parser = new index.fxp.XMLParser({
45243
44405
  ignoreAttributes: false,
45244
44406
  parseTagValue: false,
45245
44407
  isArray: (name) => {
@@ -46253,7 +45415,7 @@ exports.config = void 0;
46253
45415
  exports.handler = void 0;
46254
45416
  exports.appConfig = void 0;
46255
45417
  exports.container = void 0;
46256
- path$1.dirname(require$$0$a.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index-0wA94Agk.js', document.baseURI).href))));
45418
+ path$1.dirname(require$$0$a.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index-BvslFWVg.cjs', document.baseURI).href))));
46257
45419
  const authMiddleware = (passKey) => {
46258
45420
  return async (ctx, next) => {
46259
45421
  const authHeader = ctx.headers["authorization"] || ctx.request.query.auth;