-
Notifications
You must be signed in to change notification settings - Fork 527
/
Copy pathWanfang Data.js
3424 lines (3364 loc) · 145 KB
/
Wanfang Data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"translatorID": "eb876bd2-644c-458e-8d05-bf54b10176f3",
"label": "Wanfang Data",
"creator": "Ace Strong, rnicrosoft, Xingzhong Lin, jiaojiaodubai",
"target": "^https?://(d|s|sns|c)\\.wanfangdata\\.com\\.cn",
"minVersion": "2.0rc1",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2025-01-31 12:29:28"
}
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2014 jiaojiaodubai<[email protected]>
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
const typeMap = {
periodical: {
attachmentType: 'perio',
itemType: 'journalArticle'
},
thesis: {
attachmentType: 'degree',
itemType: 'thesis'
},
conference: {
attachmentType: 'conference',
itemType: 'conferencePaper'
},
patent: {
attachmentType: 'patent',
itemType: 'patent'
},
nstr: {
// 不支持下载
itemType: 'report'
},
cstad: {
// 不支持下载
itemType: 'report'
},
standard: {
attachmentType: 'standard',
itemType: 'standard'
},
claw: {
attachmentType: 'legislations',
itemType: 'statute'
}
};
function detectWeb(doc, url) {
const dynamic = doc.querySelector('.container-flex, .periodical');
if (dynamic) {
Z.monitorDOMChanges(dynamic, { childList: true });
}
for (const key in typeMap) {
if (url.includes(`/${key}/`)) {
return typeMap[key].itemType;
}
}
if (getSearchResults(doc, true)) {
return 'multiple';
}
return false;
}
function getSearchResults(doc, checkOnly) {
const items = {};
let found = false;
// search results
if (doc.querySelector('.result-list-container')) {
const rows = doc.querySelectorAll('div.normal-list');
for (const row of rows) {
const title = text(row, '.title');
const hiddenId = text(row, 'span.title-id-hidden');
const [type, id] = hiddenId.split('_');
if (!title || !hiddenId) continue;
if (checkOnly) return true;
found = true;
items[JSON.stringify({
type,
id
})] = title;
}
}
// journal navigation
else if (doc.querySelector('wf-article-list')) {
const rows = doc.querySelectorAll('wf-article-list > wf-article-item');
for (const row of rows) {
const title = attr(row, 'input', 'value');
const id = attr(row, 'input', 'docuid');
if (!title || !id) continue;
if (checkOnly) return true;
found = true;
items[JSON.stringify({
type: 'periodical',
id
})] = title;
}
}
// cstr navigation
else if (doc.querySelector('.ivu-table')) {
const rows = doc.querySelectorAll('.ivu-table-row');
for (const row of rows) {
const title = text(row, '.title-link');
const href = attr(row, '.title-link', 'href');
const id = getIdFromUrl(href);
if (!title || !id) continue;
if (checkOnly) return true;
found = true;
items[JSON.stringify({
type: 'nstr',
id
})] = title;
}
}
return found ? items : false;
}
async function doWeb(doc, url) {
if (detectWeb(doc, url) === 'multiple') {
const items = await Zotero.selectItems(getSearchResults(doc, false));
if (!items) return;
for (const key in items) {
const { type, id } = JSON.parse(key);
await scrapeExportApi(type, id);
}
}
else {
// get attributes from bookmark button is always reliable and convenient
const type = attr(doc, '.collection > wf-favourite', 'literature_type');
const id = attr(doc, '.collection > wf-favourite', 'literature_id');
try {
// throw new Error('debug');
if (type === 'standard') {
throw new Error('for standard, it is better to scrape data from webpage');
}
await scrapeDetilApi(type, id);
}
catch (error) {
Z.debug(error);
await scrapePage(doc, type, id);
}
}
}
async function scrapePage(doc, type, id) {
const data = getLabeledData(
doc.querySelectorAll('.detailList .list'),
row => text(row, '.item').slice(0, -1),
row => row.querySelector('.item+*'),
doc.createElement('div')
);
const extra = new Extra();
const newItem = new Zotero.Item(typeMap[type].itemType);
newItem.title = text(doc, '.detailTitleCN > span:first-child') || text(doc, '.detailTitleCN');
extra.set('original-title', ZU.capitalizeTitle(text(doc, '.detailTitleEN')), true);
newItem.abstractNote = ZU.trimInternal(text(doc, '.summary > .item+*'));
doc.querySelectorAll('.author.detailTitle > .itemUrl > a').forEach((elm) => {
newItem.creators.push(cleanAuthor(elm.innerText.replace(/[\s\d,]*$/, ''), 'author'));
});
newItem.language = {
eng: 'en-US',
chi: 'zh-CN'
}[data('语种')] || 'zh-CN';
switch (newItem.itemType) {
case 'journalArticle': {
const pubInfo = text(doc, '.publishData > .item+*');
newItem.date = tryMatch(pubInfo, /^\d{4}/);
newItem.volume = tryMatch(pubInfo, /,0*(\d+)\(/, 1);
newItem.issue = tryMatch(pubInfo, /\((.+?)\)/, 1).replace(/0*(\d+)/, '$1');
newItem.publicationTitle = text(doc, '.periodicalName');
newItem.pages = tryMatch(data('页数'), /\((.+)\)/, 1)
.replace(/\b0*(\d+)/, '$1')
.replace(/\+/g, ',')
.replace(/~/g, '-');
newItem.DOI = ZU.cleanDOI(text(doc, '.doiStyle > a'));
newItem.ISSN = ZU.cleanISSN(text(doc, '.periodicalDataItem'));
break;
}
case 'thesis':
newItem.thesisType = `${text(doc, '.degree > .itemUrl')}学位论文`;
newItem.university = text(doc, '.detailOrganization');
doc.querySelectorAll('.tutor > .itemUrl > a').forEach((element) => {
newItem.creators.push(cleanAuthor(element.innerText, 'contributor'));
});
newItem.date = tryMatch(text(doc, '.thesisYear'), /\d+/);
extra.set('major', text(doc, '.major > .itemUrl'));
break;
case 'conferencePaper':
newItem.date = text(doc, '.meetingDate > .itemUrl');
newItem.proceedingsTitle = text(doc, '.mettingCorpus > .itemUrl');
newItem.conferenceName = data('会议名称');
newItem.place = text(doc, '.meetingArea > .itemUrl');
newItem.pages = text(doc, '.pageNum > .itemUrl');
extra.set('organizer', text(doc, '.sponsor > .itemUrl'), true);
break;
case 'patent':
data('发明/设计人', true).querySelectorAll('a').forEach((elemant) => {
newItem.creators.push(cleanAuthor(elemant.innerText, 'inventor'));
});
data('代理人', true).querySelectorAll('.multi-sep').forEach((elemant) => {
newItem.creators.push(cleanAuthor(elemant.innerText, 'attorneyAgent'));
});
newItem.patentNumber = text(doc, '.publicationNo > .itemUrl a') || tryMatch(text(doc, '.publicationNo > .itemUrl'), /\w+/);
newItem.applicationNumber = text(doc, '.patentCode > .itemUrl');
newItem.country = newItem.place = patentCountry(newItem.patentNumber || newItem.applicationNumber);
newItem.assignee = data('申请/专利权人');
newItem.filingDate = data('申请日期');
newItem.priorityNumbers = data('优先权');
newItem.issueDate = data('公开/公告日');
newItem.legalStatus = text(doc, '.periodicalContent .messageTime > span:last-child');
newItem.rights = text(doc, '.signoryItem > .itemUrl');
extra.set('genre', text(doc, '.patentType > .itemUrl'), true);
break;
case 'report':
newItem.institution = text(doc, '.organization > .itemUrl');
if (type === 'nstr') {
newItem.reportType = {
'en-US': 'Science and technology report',
'zh-CN': '科技报告'
}[newItem.language];
newItem.date = text(doc, '.preparationTime > .itemUrl');
newItem.archiveLocation = text(doc, '.libNum > .itemUrl');
}
else if (type === 'cstad') {
newItem.abstractNote = text(doc, '.abstract > .itemUrl');
newItem.reportType = {
'en-US': 'Achievement report',
'zh-CN': '成果报告'
}[newItem.language];
newItem.reportNumber = text(doc, '.id > .itemUrl');
newItem.date = text(doc, '.publishYear > .itemUrl');
extra.set('project', text(doc, '.projectName > .itemUrl'));
doc.querySelectorAll('.creator.list .multi-sep').forEach((elm) => {
newItem.creators.push(cleanAuthor(elm.innerText));
});
}
break;
case 'standard':
newItem.title = text(doc, '.detailTitleCN').replace(/([\u4e00-\u9fff])\s+([\u4e00-\u9fff])/, '$1 $2');
newItem.number = text(doc, '.standardId > .itemUrl').replace('-', '—');
newItem.date = text(doc, '.issueDate > .itemUrl');
newItem.publisher = data('出版单位');
newItem.status = text(doc, '.status > .itemUrl');
extra.set('CCS', text(doc, '.ccsCode > .itemUrl'));
extra.set('ICS', text(doc, '.ICSCode > .itemUrl'));
extra.set('applyDate', text(doc, '.applyDate > .itemUrl'));
extra.set('substitute', text(doc, '.newStandard > .itemUrl'));
extra.set('reference', text(doc, '.citeStandard > .itemKeyword'));
extra.set('adopted', text(doc, '.adoptStandard > .itemUrl'));
newItem.creators.push(cleanAuthor(text(doc, '.technicalCommittee > .itemUrl').replace(/\(.+?\)$/, '')));
break;
case 'statute':
if (/(\d{4}.*)$/.test(newItem.title)) {
extra.set('edition', tryMatch(newItem.title, /((\d{4}.*))$/, 1), true);
newItem.title = tryMatch(newItem.title, /(^.+)(.+?)$/, 1);
}
if (newItem.title.startsWith('中华人民共和国')) {
newItem.shortTitle = newItem.title.substring(7);
}
newItem.publicLawNumber = text(doc, '.issueNumber > .itemUrl');
newItem.dateEnacted = text(doc, '.issueDate > .itemUrl');
if (!text(doc, '.effectLevel > .itemUrl').includes('法律')) {
extra.set('type', 'regulation', true);
}
if (text(doc, '.effect > .itemUrl') === '失效') {
extra.set('status', '已废止', true);
}
extra.set('applyDate', text(doc, '.applyDate > .itemUrl'));
text(doc, '.issueUnit > .itemUrl').split(/[;,;、]\s?/).forEach(string => newItem.creators.push(cleanAuthor(string)));
break;
}
newItem.url = `https://d.wanfangdata.com.cn/${type}/${id}`;
extra.set('CLC', text(doc, '.classify > .itemUrl, .classCodeMapping > .itemUrl'));
doc.querySelectorAll('.keyword > .item+* > a, .keywordEN > .item+* > a').forEach((elm) => {
newItem.tags.push(elm.innerText);
});
const attachmentType = typeMap[type].attachmentType;
if (attachmentType) {
newItem.attachments.push({
url: encodeURI('https://oss.wanfangdata.com.cn/www/'
+ `${doc.title}.ashx?`
+ 'isread=true'
+ `&type=${attachmentType}`
+ `&resourceId=${id}`),
title: 'Full Text PDF',
mimeType: 'application/pdf'
});
}
newItem.extra = extra.toString();
newItem.complete();
}
function getLabeledData(rows, labelGetter, dataGetter, defaultElm) {
const labeledElm = {};
for (const row of rows) {
labeledElm[labelGetter(row, rows)] = dataGetter(row, rows);
}
const data = (labels, element = false) => {
if (Array.isArray(labels)) {
for (const label of labels) {
const result = data(label, element);
if (result) return result;
}
return element ? defaultElm : '';
}
const targetElm = labeledElm[labels];
return targetElm
? element ? targetElm : ZU.trimInternal(targetElm.textContent)
: element ? defaultElm : '';
};
return data;
}
async function scrapeDetilApi(type, id) {
const reqMassage = DetailInfoRequest.create({
resourcetype: type.charAt(0).toUpperCase() + type.substring(1),
id: id
});
const decoder = new TextDecoder();
const reqBuffer = prependHead(DetailInfoRequest.encode(reqMassage).finish());
const respond = await request('/Detail.DetailService/getDetailInFormation', {
method: 'POST',
body: decoder.decode(reqBuffer),
headers: {
'Content-Type': 'application/grpc-web+proto',
Referer: `https://d.wanfangdata.com.cn/${type}/${id}`
},
// responseType: 'arraybuffer',
responseCharset: 'x-user-defined'
});
const headLength = 5;
// https://groups.google.com/g/zotero-dev/c/gjfM2QK08p4
const resBuffer = new Uint8Array(respond.body.length - headLength);
for (let x = 0; x < respond.body.length; x++) {
resBuffer[x] = respond.body.charCodeAt(x + headLength) & 0xff;
}
const resObject = DetailResponse.toObject(DetailResponse.decode(resBuffer), { defaults: true });
Z.debug(resObject);
parseJson(resObject.detail[0][type === 'cstad' ? 'cstadt' : type]);
}
async function scrapeExportApi(type, id) {
const reqMsg = ExportRequest.create({ hiddenid: `${type}_${id}` });
const reqBuffer = prependHead(ExportRequest.encode(reqMsg).finish());
const decoder = new TextDecoder('utf-8');
const respond = await request('https://s.wanfangdata.com.cn/WwwService.ExportService/export', {
method: 'POST',
body: decoder.decode(reqBuffer),
headers: {
'Content-Type': 'application/grpc-web+proto'
},
responseCharset: 'x-user-defined'
});
// https://groups.google.com/g/zotero-dev/c/gjfM2QK08p4
const resBuffer = new Uint8Array(respond.body.length);
for (let i = 0; i < respond.body.length; i++) {
resBuffer[i] = respond.body.charCodeAt(i) & 0xff;
}
const head = resBuffer.slice(0, 5);
let hexStrHead = '';
for (let i = 0; i < head.length; i++) {
hexStrHead += head[i].toString(16).padStart(2, '0');
}
const pbLength = parseInt(hexStrHead, 16);
const targetBuffer = resBuffer.slice(5, 5 + pbLength);
const resObject = ExportResponse.toObject(ExportResponse.decode(targetBuffer), { defaults: true });
parseJson(resObject.resourceList[0][type === 'cstad' ? 'cstadt' : type], type, id);
}
function prependHead(body) {
let length = body.length;
const head = new Uint8Array(5);
for (let i = 0; i < 5; ++i) {
head[4 - i] = length & 0xff;
length >>= 8;
}
const fullBuffer = new Uint8Array(head.length + body.length);
fullBuffer.set(head, 0);
fullBuffer.set(body, head.length);
return fullBuffer;
}
function parseJson(json, type, id) {
const extra = new Extra();
const newItem = new Z.Item(typeMap[type].itemType);
newItem.title = json.titleList[0];
extra.set('original-title', ZU.capitalizeTitle(json.titleList[1] || ''), true);
newItem.abstractNote = ZU.trimInternal(json.abstractList[0] || '');
newItem.language = {
eng: 'en-US',
chi: 'zh-CN'
}[json.language] || 'zh-CN';
switch (newItem.itemType) {
case 'journalArticle': {
newItem.publicationTitle = json.periodicaltitleList[0];
extra.set('original-container-title', json.periodicaltitleList[1], true);
newItem.volume = json.volum;
newItem.issue = json.issue;
newItem.pages = json.page;
newItem.date = ZU.strToISO(json.publishdate || '');
newItem.ISSN = json.issn;
extra.set('fund', json.fundList.join(', '));
const creators = [];
for (let i = 0; i < json.creatorList.length; i++) {
const creator = cleanAuthor(json.creatorList[i]);
newItem.creators.push(JSON.parse(JSON.stringify(creator)));
if (json.foreigncreatorList[i]) {
const enCreator = cleanAuthor(ZU.capitalizeName(json.foreigncreatorList[i]));
const enCreatorStr = `${enCreator.firstName} || ${enCreator.lastName}`;
creator.original = enCreatorStr;
extra.push('original-creator', enCreatorStr, true);
}
creators.push(creator);
}
if (creators.some(creator => creator.original)) {
extra.set('creatorsExt', JSON.stringify(creators));
}
break;
}
case 'thesis':
newItem.thesisType = `${json.degree}学位论文`;
newItem.date = ZU.strToISO(json.publishdate || '');
newItem.university = json.organizationnewList[0];
newItem.numPages = json.pageno;
json.creatorList.forEach(name => newItem.creators.push(cleanAuthor(name)));
json.tutorList.forEach(name => newItem.creators.push(cleanAuthor(name, 'contributor')));
extra.set('major', json.major);
break;
case 'conferencePaper':
newItem.date = ZU.strToISO(json.publishdate || '');
newItem.proceedingsTitle = json.meetingcorpus;
newItem.conferenceName = json.meetingtitleList[0];
newItem.place = json.meetingarea;
newItem.pages = json.page;
json.creatorList.forEach(name => newItem.creators.push(cleanAuthor(name)));
break;
case 'patent':
newItem.patentNumber = json.publicationno;
newItem.applicationNumber = json.patentcode;
newItem.place = newItem.country = patentCountry(newItem.patentNumber || newItem.applicationNumber);
newItem.assignee = json.applicantList.json(', ');
newItem.filingDate = ZU.strToISO(json.applicationdate);
newItem.priorityNumbers = json.priorityList.join(', ');
newItem.issueDate = ZU.strToISO(json.publicationdate);
newItem.legalStatus = json.legalstatus;
extra.set('genre', json.patenttype, true);
json.inventorList.forEach(name => newItem.creators.push(cleanAuthor(name, 'inventor')));
json.agent.split('%').forEach(name => newItem.creators.push(cleanAuthor(name, 'attorneyAgent')));
break;
case 'report':
if (type === 'nstr') {
newItem.reportType = {
'en-US': 'Science and technology report',
'zh-CN': '科技报告'
}[newItem.language];
newItem.reportNumber = json.id;
newItem.place = json.area;
newItem.institution = json.organizationList.join(', ');
newItem.date = ZU.strToISO(json.publishdate);
extra.set('project', json.projectname);
json.creatorList.forEach(name => newItem.creators.push(cleanAuthor(name)));
}
else if (type === 'cstad') {
newItem.date = ZU.strToISO(json.publishdate);
newItem.reportType = {
'en-US': 'Achievement report',
'zh-CN': '成果报告'
}[newItem.language];
extra.set('fund', json.page);
json.creatorList.forEach(name => newItem.creators.push(cleanAuthor(name)));
}
break;
case 'standard':
newItem.title = json.titleList[0].replace(/([\u4e00-\u9fff])\s+([\u4e00-\u9fff])/, '$1 $2');
newItem.number = json.standardno;
newItem.date = ZU.strToISO(json.publishdate);
newItem.publisher = json.sourcedbList[0];
newItem.status = json.status;
extra.set('CCS', json.ccscodeList.at(-1));
extra.set('CCS', json.icscodeList.at(-1));
// Viewing paid fields requires sending a request with transaction information, but simulating transactions is difficult
extra.set('applyDate', ZU.strToISO(json.applydate || ''));
break;
case 'statute':
if (/(\d{4}.*)$/.test(newItem.title)) {
extra.set('edition', tryMatch(newItem.title, /((\d{4}.*))$/, 1), true);
newItem.title = tryMatch(newItem.title, /(^.+)(.+?)$/, 1);
}
if (newItem.title.startsWith('中华人民共和国')) {
newItem.shortTitle = newItem.title.substring(7);
}
newItem.publicLawNumber = json.issuenumber;
newItem.dateEnacted = ZU.strToISO(json.issuedate || '');
if (json.effectlevel.includes('法律')) {
extra.set('type', 'regulation', true);
}
if (json.effect === '失效') {
extra.set('status', '已废止', true);
}
extra.set('applyDate', json.applydate);
json.issueunitList.forEach(name => newItem.creators.push(cleanAuthor(name)));
break;
}
if (ZU.fieldIsValidForType('DOI', newItem.itemType)) {
newItem.DOI = json.doi;
}
else {
extra.set('DOI', json.doi, true);
}
newItem.url = `https://d.wanfangdata.com.cn/${type}/${id}`;
extra.set('citation', json.citedcount);
json.classcodeList && extra.set('CLC', json.classcodeList.join(', '));
newItem.tags = json.keywordsList;
if (json.hasfulltext) {
newItem.attachments.push({
url: json.fulltextpath,
title: 'Full Text PDF',
mimeType: 'application/pdf'
});
}
newItem.extra = extra.toString();
newItem.complete();
}
class Extra {
constructor() {
this.fields = [];
}
push(key, val, csl = false) {
this.fields.push({ key: key, val: val, csl: csl });
}
set(key, val, csl = false) {
let target = this.fields.find(obj => new RegExp(`^${key}$`, 'i').test(obj.key));
if (target) {
target.val = val;
}
else {
this.push(key, val, csl);
}
}
get(key) {
let result = this.fields.find(obj => new RegExp(`^${key}$`, 'i').test(obj.key));
return result
? result.val
: undefined;
}
toString(history = '') {
this.fields = this.fields.filter(obj => obj.val);
return [
this.fields.filter(obj => obj.csl).map(obj => `${obj.key}: ${obj.val}`).join('\n'),
history,
this.fields.filter(obj => !obj.csl).map(obj => `${obj.key}: ${obj.val}`).join('\n')
].filter(obj => obj).join('\n');
}
}
function tryMatch(string, pattern, index = 0) {
let match = string.match(pattern);
return match && match[index]
? match[index]
: '';
}
function cleanAuthor(creator, creatorType = 'author') {
creator = ZU.cleanAuthor(creator, creatorType);
if (/[\u4e00-\u9fff]/.test(creator.lastName)) {
creator.fieldMode = 1;
}
return creator;
}
function patentCountry(idNumber) {
return {
AD: '安道尔', AE: '阿拉伯联合酋长国', AF: '阿富汗', AG: '安提瓜和巴布达', AI: '安圭拉', AL: '阿尔巴尼亚', AM: '亚美尼亚', AN: '菏属安的列斯群岛', AO: '安哥拉', AR: '阿根廷', AT: '奥地利', AU: '澳大利亚', AW: '阿鲁巴', AZ: '阿塞拜疆', BB: '巴巴多斯', BD: '孟加拉国', BE: '比利时', BF: '布莱基纳法索', BG: '保加利亚', BH: '巴林', BI: '布隆迪', BJ: '贝宁', BM: '百慕大', BN: '文莱', BO: '玻利维亚', BR: '巴西', BS: '巴哈马', BT: '不丹', BU: '缅甸', BW: '博茨瓦纳', BY: '白俄罗斯', BZ: '伯利兹', CA: '加拿大', CF: '中非共和国', CG: '刚果', CH: '瑞士', CI: '科特迪瓦', CL: '智利', CM: '喀麦隆', CN: '中国', CO: '哥伦比亚', CR: '哥斯达黎加', CS: '捷克斯洛伐克', CU: '古巴', CV: '怫得角', CY: '塞浦路斯',
DE: '联邦德国', DJ: '吉布提', DK: '丹麦', DM: '多米尼加岛', DO: '多米尼加共和国', DZ: '阿尔及利亚', EC: '厄瓜多尔', EE: '爱沙尼亚', EG: '埃及', EP: '欧洲专利局', ES: '西班牙', ET: '埃塞俄比亚', FI: '芬兰', FJ: '斐济', FK: '马尔维纳斯群岛', FR: '法国',
GA: '加蓬', GB: '英国', GD: '格林那达', GE: '格鲁吉亚', GH: '加纳', GI: '直布罗陀', GM: '冈比亚', GN: '几内亚', GQ: '赤道几内亚', GR: '希腊', GT: '危地马拉', GW: '几内亚比绍', GY: '圭亚那', HK: '香港', HN: '洪都拉斯', HR: '克罗地亚', HT: '海地', HU: '匈牙利', HV: '上沃尔特', ID: '印度尼西亚', IE: '爱尔兰', IL: '以色列', IN: '印度', IQ: '伊拉克', IR: '伊朗', IS: '冰岛', IT: '意大利',
JE: '泽西岛', JM: '牙买加', JO: '约旦', JP: '日本', KE: '肯尼亚', KG: '吉尔吉斯', KH: '柬埔寨', KI: '吉尔伯特群岛', KM: '科摩罗', KN: '圣克里斯托夫岛', KP: '朝鲜', KR: '韩国', KW: '科威特', KY: '开曼群岛', KZ: '哈萨克', LA: '老挝', LB: '黎巴嫩', LC: '圣卢西亚岛', LI: '列支敦士登', LK: '斯里兰卡', LR: '利比里亚', LS: '莱索托', LT: '立陶宛', LU: '卢森堡', LV: '拉脱维亚', LY: '利比亚',
MA: '摩洛哥', MC: '摩纳哥', MD: '莫尔多瓦', MG: '马达加斯加', ML: '马里', MN: '蒙古', MO: '澳门', MR: '毛里塔尼亚', MS: '蒙特塞拉特岛', MT: '马耳他', MU: '毛里求斯', MV: '马尔代夫', MW: '马拉维', MX: '墨西哥', MY: '马来西亚', MZ: '莫桑比克', NA: '纳米比亚', NE: '尼日尔', NG: '尼日利亚', NH: '新赫布里底', NI: '尼加拉瓜', NL: '荷兰', NO: '挪威', NP: '尼泊尔', NR: '瑙鲁', NZ: '新西兰', OA: '非洲知识产权组织', OM: '阿曼',
PA: '巴拿马', PC: 'PCT', PE: '秘鲁', PG: '巴布亚新几内亚', PH: '菲律宾', PK: '巴基斯坦', PL: '波兰', PT: '葡萄牙', PY: '巴拉圭', QA: '卡塔尔', RO: '罗马尼亚', RU: '俄罗斯联邦', RW: '卢旺达',
SA: '沙特阿拉伯', SB: '所罗门群岛', SC: '塞舌尔', SD: '苏丹', SE: '瑞典', SG: '新加坡', SH: '圣赫勒拿岛', SI: '斯洛文尼亚', SL: '塞拉利昂', SM: '圣马利诺', SN: '塞内加尔', SO: '索马里', SR: '苏里南', ST: '圣多美和普林西比岛', SU: '苏联', SV: '萨尔瓦多', SY: '叙利亚', SZ: '斯威士兰', TD: '乍得', TG: '多哥', TH: '泰国', TJ: '塔吉克', TM: '土库曼', TN: '突尼斯', TO: '汤加', TR: '土耳其', TT: '特立尼达和多巴哥', TV: '图瓦卢', TZ: '坦桑尼亚', UA: '乌克兰', UG: '乌干达', US: '美国', UY: '乌拉圭', UZ: '乌兹别克',
VA: '梵蒂冈', VC: '圣文森特岛和格林纳达', VE: '委内瑞拉', VG: '维尔京群岛', VN: '越南', VU: '瓦努阿图', WO: '世界知识产权组织', WS: '萨摩亚', YD: '民主也门', YE: '也门', YU: '南斯拉夫', ZA: '南非', ZM: '赞比亚', ZR: '扎伊尔', ZW: '津巴布韦'
}[idNumber.substring(0, 2).toUpperCase()] || '';
}
function getIdFromUrl(url) {
const urlObj = new URL(url);
const pathParts = urlObj.pathname.split('/');
const deURI = decodeURIComponent(pathParts[2]);
const deBase64 = atob(deURI);
const encoder = new TextEncoder();
const buffer = encoder.encode(deBase64);
// make a cocy to avoid Error: Accessing TypedArray data over Xrays is slow, and forbidden in order to encourage performant code.
const urlMsg = Url.decode(new Uint8Array(buffer));
return Url.toObject(urlMsg).id;
}
/**
* for visually viewing binary data during debugging
*/
// eslint-disable-next-line no-unused-vars
function bytesToHex(bytes) {
const hex = [];
for (let i = 0; i < bytes.length; i++) {
hex.push((bytes[i] >>> 4).toString(16));
hex.push((bytes[i] & 0xF).toString(16));
}
return hex.join('');
}
/* eslint-disable */
/*!
* protobuf.js v7.4.0 (c) 2016, daniel wirtz
* compiled thu, 22 aug 2024 20:30:39 utc
* licensed under the bsd-3-clause license
* see: https://github.com/dcodeio/protobuf.js for details
*/
!function(d){"use strict";!function(r,u,t){var n=function t(n){var i=u[n];return i||r[n][0].call(i=u[n]={exports:{}},t,i,i.exports),i.exports}(t[0]);n.util.global.protobuf=n,"function"==typeof define&&define.amd&&define(["long"],function(t){return t&&t.isLong&&(n.util.Long=t,n.configure()),n}),"object"==typeof module&&module&&module.exports&&(module.exports=n)}({1:[function(t,n,i){n.exports=function(t,n){var i=Array(arguments.length-1),e=0,r=2,s=!0;for(;r<arguments.length;)i[e++]=arguments[r++];return new Promise(function(r,u){i[e]=function(t){if(s)if(s=!1,t)u(t);else{for(var n=Array(arguments.length-1),i=0;i<n.length;)n[i++]=arguments[i];r.apply(null,n)}};try{t.apply(n||null,i)}catch(t){s&&(s=!1,u(t))}})}},{}],2:[function(t,n,i){i.length=function(t){var n=t.length;if(!n)return 0;for(var i=0;1<--n%4&&"="==(t[0|n]||"");)++i;return Math.ceil(3*t.length)/4-i};for(var f=Array(64),o=Array(123),r=0;r<64;)o[f[r]=r<26?r+65:r<52?r+71:r<62?r-4:r-59|43]=r++;i.encode=function(t,n,i){for(var r,u=null,e=[],s=0,h=0;n<i;){var o=t[n++];switch(h){case 0:e[s++]=f[o>>2],r=(3&o)<<4,h=1;break;case 1:e[s++]=f[r|o>>4],r=(15&o)<<2,h=2;break;case 2:e[s++]=f[r|o>>6],e[s++]=f[63&o],h=0}8191<s&&((u=u||[]).push(String.fromCharCode.apply(String,e)),s=0)}return h&&(e[s++]=f[r],e[s++]=61,1===h&&(e[s++]=61)),u?(s&&u.push(String.fromCharCode.apply(String,e.slice(0,s))),u.join("")):String.fromCharCode.apply(String,e.slice(0,s))};var c="invalid encoding";i.decode=function(t,n,i){for(var r,u=i,e=0,s=0;s<t.length;){var h=t.charCodeAt(s++);if(61==h&&1<e)break;if((h=o[h])===d)throw Error(c);switch(e){case 0:r=h,e=1;break;case 1:n[i++]=r<<2|(48&h)>>4,r=h,e=2;break;case 2:n[i++]=(15&r)<<4|(60&h)>>2,r=h,e=3;break;case 3:n[i++]=(3&r)<<6|h,e=0}}if(1===e)throw Error(c);return i-u},i.test=function(t){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t)}},{}],3:[function(t,n,i){function r(){this.t={}}(n.exports=r).prototype.on=function(t,n,i){return(this.t[t]||(this.t[t]=[])).push({fn:n,ctx:i||this}),this},r.prototype.off=function(t,n){if(t===d)this.t={};else if(n===d)this.t[t]=[];else for(var i=this.t[t],r=0;r<i.length;)i[r].fn===n?i.splice(r,1):++r;return this},r.prototype.emit=function(t){var n=this.t[t];if(n){for(var i=[],r=1;r<arguments.length;)i.push(arguments[r++]);for(r=0;r<n.length;)n[r].fn.apply(n[r++].ctx,i)}return this}},{}],4:[function(t,n,i){function r(t){function n(t,n,i,r){var u=n<0?1:0;t(0===(n=u?-n:n)?0<1/n?0:2147483648:isNaN(n)?2143289344:34028234663852886e22<n?(u<<31|2139095040)>>>0:n<11754943508222875e-54?(u<<31|Math.round(n/1401298464324817e-60))>>>0:(u<<31|127+(t=Math.floor(Math.log(n)/Math.LN2))<<23|8388607&Math.round(n*Math.pow(2,-t)*8388608))>>>0,i,r)}function i(t,n,i){t=t(n,i),n=2*(t>>31)+1,i=t>>>23&255,t&=8388607;return 255==i?t?NaN:1/0*n:0==i?1401298464324817e-60*n*t:n*Math.pow(2,i-150)*(8388608+t)}function r(t,n,i){h[0]=t,n[i]=o[0],n[i+1]=o[1],n[i+2]=o[2],n[i+3]=o[3]}function u(t,n,i){h[0]=t,n[i]=o[3],n[i+1]=o[2],n[i+2]=o[1],n[i+3]=o[0]}function e(t,n){return o[0]=t[n],o[1]=t[n+1],o[2]=t[n+2],o[3]=t[n+3],h[0]}function s(t,n){return o[3]=t[n],o[2]=t[n+1],o[1]=t[n+2],o[0]=t[n+3],h[0]}var h,o,f,c,a;function l(t,n,i,r,u,e){var s,h=r<0?1:0;0===(r=h?-r:r)?(t(0,u,e+n),t(0<1/r?0:2147483648,u,e+i)):isNaN(r)?(t(0,u,e+n),t(2146959360,u,e+i)):17976931348623157e292<r?(t(0,u,e+n),t((h<<31|2146435072)>>>0,u,e+i)):r<22250738585072014e-324?(t((s=r/5e-324)>>>0,u,e+n),t((h<<31|s/4294967296)>>>0,u,e+i)):(t(4503599627370496*(s=r*Math.pow(2,-(r=1024===(r=Math.floor(Math.log(r)/Math.LN2))?1023:r)))>>>0,u,e+n),t((h<<31|r+1023<<20|1048576*s&1048575)>>>0,u,e+i))}function v(t,n,i,r,u){n=t(r,u+n),t=t(r,u+i),r=2*(t>>31)+1,u=t>>>20&2047,i=4294967296*(1048575&t)+n;return 2047==u?i?NaN:1/0*r:0==u?5e-324*r*i:r*Math.pow(2,u-1075)*(i+4503599627370496)}function w(t,n,i){f[0]=t,n[i]=c[0],n[i+1]=c[1],n[i+2]=c[2],n[i+3]=c[3],n[i+4]=c[4],n[i+5]=c[5],n[i+6]=c[6],n[i+7]=c[7]}function b(t,n,i){f[0]=t,n[i]=c[7],n[i+1]=c[6],n[i+2]=c[5],n[i+3]=c[4],n[i+4]=c[3],n[i+5]=c[2],n[i+6]=c[1],n[i+7]=c[0]}function y(t,n){return c[0]=t[n],c[1]=t[n+1],c[2]=t[n+2],c[3]=t[n+3],c[4]=t[n+4],c[5]=t[n+5],c[6]=t[n+6],c[7]=t[n+7],f[0]}function g(t,n){return c[7]=t[n],c[6]=t[n+1],c[5]=t[n+2],c[4]=t[n+3],c[3]=t[n+4],c[2]=t[n+5],c[1]=t[n+6],c[0]=t[n+7],f[0]}return"undefined"!=typeof Float32Array?(h=new Float32Array([-0]),o=new Uint8Array(h.buffer),a=128===o[3],t.writeFloatLE=a?r:u,t.writeFloatBE=a?u:r,t.readFloatLE=a?e:s,t.readFloatBE=a?s:e):(t.writeFloatLE=n.bind(null,d),t.writeFloatBE=n.bind(null,A),t.readFloatLE=i.bind(null,p),t.readFloatBE=i.bind(null,m)),"undefined"!=typeof Float64Array?(f=new Float64Array([-0]),c=new Uint8Array(f.buffer),a=128===c[7],t.writeDoubleLE=a?w:b,t.writeDoubleBE=a?b:w,t.readDoubleLE=a?y:g,t.readDoubleBE=a?g:y):(t.writeDoubleLE=l.bind(null,d,0,4),t.writeDoubleBE=l.bind(null,A,4,0),t.readDoubleLE=v.bind(null,p,0,4),t.readDoubleBE=v.bind(null,m,4,0)),t}function d(t,n,i){n[i]=255&t,n[i+1]=t>>>8&255,n[i+2]=t>>>16&255,n[i+3]=t>>>24}function A(t,n,i){n[i]=t>>>24,n[i+1]=t>>>16&255,n[i+2]=t>>>8&255,n[i+3]=255&t}function p(t,n){return(t[n]|t[n+1]<<8|t[n+2]<<16|t[n+3]<<24)>>>0}function m(t,n){return(t[n]<<24|t[n+1]<<16|t[n+2]<<8|t[n+3])>>>0}n.exports=r(r)},{}],5:[function(t,n,i){function r(t){try{var n=eval("require")(t);if(n&&(n.length||Object.keys(n).length))return n}catch(t){}return null}n.exports=r},{}],6:[function(t,n,i){n.exports=function(n,i,t){var r=t||8192,u=r>>>1,e=null,s=r;return function(t){if(t<1||u<t)return n(t);r<s+t&&(e=n(r),s=0);t=i.call(e,s,s+=t);return 7&s&&(s=1+(7|s)),t}}},{}],7:[function(t,n,i){i.length=function(t){for(var n,i=0,r=0;r<t.length;++r)(n=t.charCodeAt(r))<128?i+=1:n<2048?i+=2:55296==(64512&n)&&56320==(64512&t.charCodeAt(r+1))?(++r,i+=4):i+=3;return i},i.read=function(t,n,i){if(i-n<1)return"";for(var r,u=null,e=[],s=0;n<i;)(r=t[n++])<128?e[s++]=r:191<r&&r<224?e[s++]=(31&r)<<6|63&t[n++]:239<r&&r<365?(r=((7&r)<<18|(63&t[n++])<<12|(63&t[n++])<<6|63&t[n++])-65536,e[s++]=55296+(r>>10),e[s++]=56320+(1023&r)):e[s++]=(15&r)<<12|(63&t[n++])<<6|63&t[n++],8191<s&&((u=u||[]).push(String.fromCharCode.apply(String,e)),s=0);return u?(s&&u.push(String.fromCharCode.apply(String,e.slice(0,s))),u.join("")):String.fromCharCode.apply(String,e.slice(0,s))},i.write=function(t,n,i){for(var r,u,e=i,s=0;s<t.length;++s)(r=t.charCodeAt(s))<128?n[i++]=r:(r<2048?n[i++]=r>>6|192:(55296==(64512&r)&&56320==(64512&(u=t.charCodeAt(s+1)))?(++s,n[i++]=(r=65536+((1023&r)<<10)+(1023&u))>>18|240,n[i++]=r>>12&63|128):n[i++]=r>>12|224,n[i++]=r>>6&63|128),n[i++]=63&r|128);return i-e}},{}],8:[function(t,n,i){var r=i;function u(){r.util.n(),r.Writer.n(r.BufferWriter),r.Reader.n(r.BufferReader)}r.build="minimal",r.Writer=t(16),r.BufferWriter=t(17),r.Reader=t(9),r.BufferReader=t(10),r.util=t(15),r.rpc=t(12),r.roots=t(11),r.configure=u,u()},{10:10,11:11,12:12,15:15,16:16,17:17,9:9}],9:[function(t,n,i){n.exports=o;var r,u=t(15),e=u.LongBits,s=u.utf8;function h(t,n){return RangeError("index out of range: "+t.pos+" + "+(n||1)+" > "+t.len)}function o(t){this.buf=t,this.pos=0,this.len=t.length}function f(){return u.Buffer?function(t){return(o.create=function(t){return u.Buffer.isBuffer(t)?new r(t):a(t)})(t)}:a}var c,a="undefined"!=typeof Uint8Array?function(t){if(t instanceof Uint8Array||Array.isArray(t))return new o(t);throw Error("illegal buffer")}:function(t){if(Array.isArray(t))return new o(t);throw Error("illegal buffer")};function l(){var t=new e(0,0),n=0;if(!(4<this.len-this.pos)){for(;n<3;++n){if(this.pos>=this.len)throw h(this);if(t.lo=(t.lo|(127&this.buf[this.pos])<<7*n)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(127&this.buf[this.pos++])<<7*n)>>>0,t}for(;n<4;++n)if(t.lo=(t.lo|(127&this.buf[this.pos])<<7*n)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(127&this.buf[this.pos])<<28)>>>0,t.hi=(t.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return t;if(n=0,4<this.len-this.pos){for(;n<5;++n)if(t.hi=(t.hi|(127&this.buf[this.pos])<<7*n+3)>>>0,this.buf[this.pos++]<128)return t}else for(;n<5;++n){if(this.pos>=this.len)throw h(this);if(t.hi=(t.hi|(127&this.buf[this.pos])<<7*n+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}function v(t,n){return(t[n-4]|t[n-3]<<8|t[n-2]<<16|t[n-1]<<24)>>>0}function w(){if(this.pos+8>this.len)throw h(this,8);return new e(v(this.buf,this.pos+=4),v(this.buf,this.pos+=4))}o.create=f(),o.prototype.i=u.Array.prototype.subarray||u.Array.prototype.slice,o.prototype.uint32=(c=4294967295,function(){if(c=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128||(c=(c|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128||(c=(c|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128||(c=(c|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128||(c=(c|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128||!((this.pos+=5)>this.len))))))return c;throw this.pos=this.len,h(this,10)}),o.prototype.int32=function(){return 0|this.uint32()},o.prototype.sint32=function(){var t=this.uint32();return t>>>1^-(1&t)|0},o.prototype.bool=function(){return 0!==this.uint32()},o.prototype.fixed32=function(){if(this.pos+4>this.len)throw h(this,4);return v(this.buf,this.pos+=4)},o.prototype.sfixed32=function(){if(this.pos+4>this.len)throw h(this,4);return 0|v(this.buf,this.pos+=4)},o.prototype.float=function(){if(this.pos+4>this.len)throw h(this,4);var t=u.float.readFloatLE(this.buf,this.pos);return this.pos+=4,t},o.prototype.double=function(){if(this.pos+8>this.len)throw h(this,4);var t=u.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,t},o.prototype.bytes=function(){var t=this.uint32(),n=this.pos,i=this.pos+t;if(i>this.len)throw h(this,t);return this.pos+=t,Array.isArray(this.buf)?this.buf.slice(n,i):n===i?(t=u.Buffer)?t.alloc(0):new this.buf.constructor(0):this.i.call(this.buf,n,i)},o.prototype.string=function(){var t=this.bytes();return s.read(t,0,t.length)},o.prototype.skip=function(t){if("number"==typeof t){if(this.pos+t>this.len)throw h(this,t);this.pos+=t}else do{if(this.pos>=this.len)throw h(this)}while(128&this.buf[this.pos++]);return this},o.prototype.skipType=function(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(t=7&this.uint32());)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+t+" at offset "+this.pos)}return this},o.n=function(t){r=t,o.create=f(),r.n();var n=u.Long?"toLong":"toNumber";u.merge(o.prototype,{int64:function(){return l.call(this)[n](!1)},uint64:function(){return l.call(this)[n](!0)},sint64:function(){return l.call(this).zzDecode()[n](!1)},fixed64:function(){return w.call(this)[n](!0)},sfixed64:function(){return w.call(this)[n](!1)}})}},{15:15}],10:[function(t,n,i){n.exports=e;var r=t(9),u=((e.prototype=Object.create(r.prototype)).constructor=e,t(15));function e(t){r.call(this,t)}e.n=function(){u.Buffer&&(e.prototype.i=u.Buffer.prototype.slice)},e.prototype.string=function(){var t=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+t,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+t,this.len))},e.n()},{15:15,9:9}],11:[function(t,n,i){n.exports={}},{}],12:[function(t,n,i){i.Service=t(13)},{13:13}],13:[function(t,n,i){n.exports=r;var h=t(15);function r(t,n,i){if("function"!=typeof t)throw TypeError("rpcImpl must be a function");h.EventEmitter.call(this),this.rpcImpl=t,this.requestDelimited=!!n,this.responseDelimited=!!i}((r.prototype=Object.create(h.EventEmitter.prototype)).constructor=r).prototype.rpcCall=function t(i,n,r,u,e){if(!u)throw TypeError("request must be specified");var s=this;if(!e)return h.asPromise(t,s,i,n,r,u);if(!s.rpcImpl)return setTimeout(function(){e(Error("already ended"))},0),d;try{return s.rpcImpl(i,n[s.requestDelimited?"encodeDelimited":"encode"](u).finish(),function(t,n){if(t)return s.emit("error",t,i),e(t);if(null===n)return s.end(!0),d;if(!(n instanceof r))try{n=r[s.responseDelimited?"decodeDelimited":"decode"](n)}catch(t){return s.emit("error",t,i),e(t)}return s.emit("data",n,i),e(null,n)})}catch(t){return s.emit("error",t,i),setTimeout(function(){e(t)},0),d}},r.prototype.end=function(t){return this.rpcImpl&&(t||this.rpcImpl(null,null,null),this.rpcImpl=null,this.emit("end").off()),this}},{15:15}],14:[function(t,n,i){n.exports=u;var r=t(15);function u(t,n){this.lo=t>>>0,this.hi=n>>>0}var e=u.zero=new u(0,0),s=(e.toNumber=function(){return 0},e.zzEncode=e.zzDecode=function(){return this},e.length=function(){return 1},u.zeroHash="\0\0\0\0\0\0\0\0",u.fromNumber=function(t){var n,i;return 0===t?e:(i=(t=(n=t<0)?-t:t)>>>0,t=(t-i)/4294967296>>>0,n&&(t=~t>>>0,i=~i>>>0,4294967295<++i&&(i=0,4294967295<++t&&(t=0))),new u(i,t))},u.from=function(t){if("number"==typeof t)return u.fromNumber(t);if(r.isString(t)){if(!r.Long)return u.fromNumber(parseInt(t,10));t=r.Long.fromString(t)}return t.low||t.high?new u(t.low>>>0,t.high>>>0):e},u.prototype.toNumber=function(t){var n;return!t&&this.hi>>>31?(t=1+~this.lo>>>0,n=~this.hi>>>0,-(t+4294967296*(n=t?n:n+1>>>0))):this.lo+4294967296*this.hi},u.prototype.toLong=function(t){return r.Long?new r.Long(0|this.lo,0|this.hi,!!t):{low:0|this.lo,high:0|this.hi,unsigned:!!t}},String.prototype.charCodeAt);u.fromHash=function(t){return"\0\0\0\0\0\0\0\0"===t?e:new u((s.call(t,0)|s.call(t,1)<<8|s.call(t,2)<<16|s.call(t,3)<<24)>>>0,(s.call(t,4)|s.call(t,5)<<8|s.call(t,6)<<16|s.call(t,7)<<24)>>>0)},u.prototype.toHash=function(){return String.fromCharCode(255&this.lo,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,255&this.hi,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)},u.prototype.zzEncode=function(){var t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this},u.prototype.zzDecode=function(){var t=-(1&this.lo);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this},u.prototype.length=function(){var t=this.lo,n=(this.lo>>>28|this.hi<<4)>>>0,i=this.hi>>>24;return 0==i?0==n?t<16384?t<128?1:2:t<2097152?3:4:n<16384?n<128?5:6:n<2097152?7:8:i<128?9:10}},{15:15}],15:[function(t,n,i){var r=i;function u(t,n,i){for(var r=Object.keys(n),u=0;u<r.length;++u)t[r[u]]!==d&&i||(t[r[u]]=n[r[u]]);return t}function e(t){function i(t,n){if(!(this instanceof i))return new i(t,n);Object.defineProperty(this,"message",{get:function(){return t}}),Error.captureStackTrace?Error.captureStackTrace(this,i):Object.defineProperty(this,"stack",{value:Error().stack||""}),n&&u(this,n)}return i.prototype=Object.create(Error.prototype,{constructor:{value:i,writable:!0,enumerable:!1,configurable:!0},name:{get:function(){return t},set:d,enumerable:!1,configurable:!0},toString:{value:function(){return this.name+": "+this.message},writable:!0,enumerable:!1,configurable:!0}}),i}r.asPromise=t(1),r.base64=t(2),r.EventEmitter=t(3),r.float=t(4),r.inquire=t(5),r.utf8=t(7),r.pool=t(6),r.LongBits=t(14),r.isNode=!!("undefined"!=typeof global&&global&&global.process&&global.process.versions&&global.process.versions.node),r.global=r.isNode&&global||"undefined"!=typeof window&&window||"undefined"!=typeof self&&self||this,r.emptyArray=Object.freeze?Object.freeze([]):[],r.emptyObject=Object.freeze?Object.freeze({}):{},r.isInteger=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t},r.isString=function(t){return"string"==typeof t||t instanceof String},r.isObject=function(t){return t&&"object"==typeof t},r.isset=r.isSet=function(t,n){var i=t[n];return null!=i&&t.hasOwnProperty(n)&&("object"!=typeof i||0<(Array.isArray(i)?i:Object.keys(i)).length)},r.Buffer=function(){try{var t=r.inquire("buffer").Buffer;return t.prototype.utf8Write?t:null}catch(t){return null}}(),r.r=null,r.u=null,r.newBuffer=function(t){return"number"==typeof t?r.Buffer?r.u(t):new r.Array(t):r.Buffer?r.r(t):"undefined"==typeof Uint8Array?t:new Uint8Array(t)},r.Array="undefined"!=typeof Uint8Array?Uint8Array:Array,r.Long=r.global.dcodeIO&&r.global.dcodeIO.Long||r.global.Long||r.inquire("long"),r.key2Re=/^true|false|0|1$/,r.key32Re=/^-?(?:0|[1-9][0-9]*)$/,r.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/,r.longToHash=function(t){return t?r.LongBits.from(t).toHash():r.LongBits.zeroHash},r.longFromHash=function(t,n){t=r.LongBits.fromHash(t);return r.Long?r.Long.fromBits(t.lo,t.hi,n):t.toNumber(!!n)},r.merge=u,r.lcFirst=function(t){return(t[0]||"").toLowerCase()+t.substring(1)},r.newError=e,r.ProtocolError=e("ProtocolError"),r.oneOfGetter=function(t){for(var i={},n=0;n<t.length;++n)i[t[n]]=1;return function(){for(var t=Object.keys(this),n=t.length-1;-1<n;--n)if(1===i[t[n]]&&this[t[n]]!==d&&null!==this[t[n]])return t[n]}},r.oneOfSetter=function(i){return function(t){for(var n=0;n<i.length;++n)i[n]!==t&&delete this[i[n]]}},r.toJSONOptions={longs:String,enums:String,bytes:String,json:!0},r.n=function(){var i=r.Buffer;i?(r.r=i.from!==Uint8Array.from&&i.from||function(t,n){return new i(t,n)},r.u=i.allocUnsafe||function(t){return new i(t)}):r.r=r.u=null}},{1:1,14:14,2:2,3:3,4:4,5:5,6:6,7:7}],16:[function(t,n,i){n.exports=a;var r,u=t(15),e=u.LongBits,s=u.base64,h=u.utf8;function o(t,n,i){this.fn=t,this.len=n,this.next=d,this.val=i}function f(){}function c(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}function a(){this.len=0,this.head=new o(f,0,0),this.tail=this.head,this.states=null}function l(){return u.Buffer?function(){return(a.create=function(){return new r})()}:function(){return new a}}function v(t,n,i){n[i]=255&t}function w(t,n){this.len=t,this.next=d,this.val=n}function b(t,n,i){for(;t.hi;)n[i++]=127&t.lo|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;127<t.lo;)n[i++]=127&t.lo|128,t.lo=t.lo>>>7;n[i++]=t.lo}function y(t,n,i){n[i]=255&t,n[i+1]=t>>>8&255,n[i+2]=t>>>16&255,n[i+3]=t>>>24}a.create=l(),a.alloc=function(t){return new u.Array(t)},u.Array!==Array&&(a.alloc=u.pool(a.alloc,u.Array.prototype.subarray)),a.prototype.e=function(t,n,i){return this.tail=this.tail.next=new o(t,n,i),this.len+=n,this},(w.prototype=Object.create(o.prototype)).fn=function(t,n,i){for(;127<t;)n[i++]=127&t|128,t>>>=7;n[i]=t},a.prototype.uint32=function(t){return this.len+=(this.tail=this.tail.next=new w((t>>>=0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this},a.prototype.int32=function(t){return t<0?this.e(b,10,e.fromNumber(t)):this.uint32(t)},a.prototype.sint32=function(t){return this.uint32((t<<1^t>>31)>>>0)},a.prototype.int64=a.prototype.uint64=function(t){t=e.from(t);return this.e(b,t.length(),t)},a.prototype.sint64=function(t){t=e.from(t).zzEncode();return this.e(b,t.length(),t)},a.prototype.bool=function(t){return this.e(v,1,t?1:0)},a.prototype.sfixed32=a.prototype.fixed32=function(t){return this.e(y,4,t>>>0)},a.prototype.sfixed64=a.prototype.fixed64=function(t){t=e.from(t);return this.e(y,4,t.lo).e(y,4,t.hi)},a.prototype.float=function(t){return this.e(u.float.writeFloatLE,4,t)},a.prototype.double=function(t){return this.e(u.float.writeDoubleLE,8,t)};var g=u.Array.prototype.set?function(t,n,i){n.set(t,i)}:function(t,n,i){for(var r=0;r<t.length;++r)n[i+r]=t[r]};a.prototype.bytes=function(t){var n,i=t.length>>>0;return i?(u.isString(t)&&(n=a.alloc(i=s.length(t)),s.decode(t,n,0),t=n),this.uint32(i).e(g,i,t)):this.e(v,1,0)},a.prototype.string=function(t){var n=h.length(t);return n?this.uint32(n).e(h.write,n,t):this.e(v,1,0)},a.prototype.fork=function(){return this.states=new c(this),this.head=this.tail=new o(f,0,0),this.len=0,this},a.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new o(f,0,0),this.len=0),this},a.prototype.ldelim=function(){var t=this.head,n=this.tail,i=this.len;return this.reset().uint32(i),i&&(this.tail.next=t.next,this.tail=n,this.len+=i),this},a.prototype.finish=function(){for(var t=this.head.next,n=this.constructor.alloc(this.len),i=0;t;)t.fn(t.val,n,i),i+=t.len,t=t.next;return n},a.n=function(t){r=t,a.create=l(),r.n()}},{15:15}],17:[function(t,n,i){n.exports=e;var r=t(16),u=((e.prototype=Object.create(r.prototype)).constructor=e,t(15));function e(){r.call(this)}function s(t,n,i){t.length<40?u.utf8.write(t,n,i):n.utf8Write?n.utf8Write(t,i):n.write(t,i)}e.n=function(){e.alloc=u.u,e.writeBytesBuffer=u.Buffer&&u.Buffer.prototype instanceof Uint8Array&&"set"===u.Buffer.prototype.set.name?function(t,n,i){n.set(t,i)}:function(t,n,i){if(t.copy)t.copy(n,i,0,t.length);else for(var r=0;r<t.length;)n[i++]=t[r++]}},e.prototype.bytes=function(t){var n=(t=u.isString(t)?u.r(t,"base64"):t).length>>>0;return this.uint32(n),n&&this.e(e.writeBytesBuffer,n,t),this},e.prototype.string=function(t){var n=u.Buffer.byteLength(t);return this.uint32(n),n&&this.e(s,n,t),this},e.n()},{15:15,16:16}]},{},[8])}();
//# sourceMappingURL=protobuf.min.js.map
// Common aliases
const $Reader = protobuf.Reader, $util = protobuf.util, $Writer = protobuf.Writer;
const $root = protobuf.roots.default || (protobuf.roots.default = {});
/* below codes are generated by protobuf-cli */
const DetailInfoRequest = $root.DetailInfoRequest = (() => {
function DetailInfoRequest(properties) {
if (properties)
for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
DetailInfoRequest.prototype.resourcetype = "";
DetailInfoRequest.prototype.id = "";
DetailInfoRequest.prototype.referer = "";
DetailInfoRequest.prototype.md5id = "";
DetailInfoRequest.prototype.transaction = "";
DetailInfoRequest.prototype.isFetchAccountField = false;
DetailInfoRequest.create = function create(properties) {
return new DetailInfoRequest(properties);
};
DetailInfoRequest.encode = function encode(message, writer) {
if (!writer)
writer = $Writer.create();
if (message.resourcetype != null && Object.hasOwnProperty.call(message, "resourcetype"))
writer.uint32(10).string(message.resourcetype);
if (message.id != null && Object.hasOwnProperty.call(message, "id"))
writer.uint32(18).string(message.id);
if (message.referer != null && Object.hasOwnProperty.call(message, "referer"))
writer.uint32(26).string(message.referer);
if (message.md5id != null && Object.hasOwnProperty.call(message, "md5id"))
writer.uint32(34).string(message.md5id);
if (message.transaction != null && Object.hasOwnProperty.call(message, "transaction"))
writer.uint32(42).string(message.transaction);
if (message.isFetchAccountField != null && Object.hasOwnProperty.call(message, "isFetchAccountField"))
writer.uint32(48).bool(message.isFetchAccountField);
return writer;
};
return DetailInfoRequest;
})();
const DetailResponse = $root.DetailResponse = (() => {
function DetailResponse(properties) {
this.detail = [];
this.extradataMap = {};
if (properties)
for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
DetailResponse.prototype.detail = $util.emptyArray;
DetailResponse.prototype.extradataMap = $util.emptyObject;
DetailResponse.decode = function decode(reader, length) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
let end = length === undefined ? reader.len : reader.pos + length, message = new $root.DetailResponse(), key, value;
while (reader.pos < end) {
let tag = reader.uint32();
switch (tag >>> 3) {
case 1:
if (!(message.detail && message.detail.length))
message.detail = [];
message.detail.push($root.Resource.decode(reader, reader.uint32()));
break;
case 2:
if (message.extradataMap === $util.emptyObject)
message.extradataMap = {};
let end2 = reader.uint32() + reader.pos;
key = '';
value = '';
while (reader.pos < end2) {
let tag2 = reader.uint32();
switch (tag2 >>> 3) {
case 1:
key = reader.string();
break;
case 2:
value = reader.string();
break;
default:
reader.skipType(tag2 & 7);
break;
}
}
message.extradataMap[key] = value;
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
DetailResponse.toObject = function toObject(message, options) {
if (!options)
options = {};
let object = {};
if (options.arrays || options.defaults)
object.detail = [];
if (options.objects || options.defaults)
object.extradataMap = {};
if (message.detail && message.detail.length) {
object.detail = [];
for (let j = 0; j < message.detail.length; ++j)
object.detail[j] = $root.Resource.toObject(message.detail[j], options);
}
let keys2;
if (message.extradataMap && (keys2 = Object.keys(message.extradataMap)).length) {
object.extradataMap = {};
for (let j = 0; j < keys2.length; ++j)
object.extradataMap[keys2[j]] = message.extradataMap[keys2[j]];
}
return object;
};
return DetailResponse;
})();
const Resource = $root.Resource = (() => {
function Resource(properties) {
if (properties)
for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
Resource.prototype.periodical = null;
Resource.prototype.thesis = null;
Resource.prototype.patent = null;
Resource.prototype.conference = null;
Resource.prototype.standard = null;
Resource.prototype.nstr = null;
Resource.prototype.cstadt = null;
Resource.prototype.claw = null;
Resource.decode = function decode(reader, length) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
let end = length === undefined ? reader.len : reader.pos + length, message = new $root.Resource();
while (reader.pos < end) {
let tag = reader.uint32();
switch (tag >>> 3) {
case 103:
message.periodical = $root.Periodical.decode(reader, reader.uint32());
break;
case 104:
message.thesis = $root.Thesis.decode(reader, reader.uint32());
break;
case 105:
message.patent = $root.Patent.decode(reader, reader.uint32());
break;
case 109:
message.conference = $root.Conference.decode(reader, reader.uint32());
break;
case 110:
message.standard = $root.Standard.decode(reader, reader.uint32());
break;
case 111:
message.nstr = $root.Nstr.decode(reader, reader.uint32());
break;
case 112:
message.cstadt = $root.Cstad.decode(reader, reader.uint32());
break;
case 113:
message.claw = $root.Claw.decode(reader, reader.uint32());
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
Resource.toObject = function toObject(message, options) {
if (!options)
options = {};
let object = {};
if (options.defaults) {
object.periodical = null;
object.thesis = null;
object.patent = null;
object.conference = null;
object.standard = null;
object.nstr = null;
object.cstadt = null;
object.claw = null;
}
if (message.periodical != null && message.hasOwnProperty('periodical'))
object.periodical = $root.Periodical.toObject(message.periodical, options);
if (message.thesis != null && message.hasOwnProperty('thesis'))
object.thesis = $root.Thesis.toObject(message.thesis, options);
if (message.patent != null && message.hasOwnProperty('patent'))
object.patent = $root.Patent.toObject(message.patent, options);
if (message.conference != null && message.hasOwnProperty('conference'))
object.conference = $root.Conference.toObject(message.conference, options);
if (message.standard != null && message.hasOwnProperty('standard'))
object.standard = $root.Standard.toObject(message.standard, options);
if (message.nstr != null && message.hasOwnProperty('nstr'))
object.nstr = $root.Nstr.toObject(message.nstr, options);
if (message.cstadt != null && message.hasOwnProperty('cstadt'))
object.cstadt = $root.Cstad.toObject(message.cstadt, options);
if (message.claw != null && message.hasOwnProperty('claw'))
object.claw = $root.Claw.toObject(message.claw, options);
return object;
};
return Resource;
})();
const ExportRequest = $root.ExportRequest = (() => {
function ExportRequest(properties) {
if (properties)
for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
ExportRequest.prototype.hiddenid = "";
ExportRequest.create = function create(properties) {
return new ExportRequest(properties);
};
ExportRequest.encode = function encode(message, writer) {
if (!writer)
writer = $Writer.create();
if (message.hiddenid != null && Object.hasOwnProperty.call(message, "hiddenid"))
writer.uint32(10).string(message.hiddenid);
return writer;
};
return ExportRequest;
})();
const ExportResponse = $root.ExportResponse = (() => {
function ExportResponse(properties) {
this.resourceList = [];
if (properties)
for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
ExportResponse.prototype.resourceList = $util.emptyArray;
ExportResponse.decode = function decode(reader, length) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
let end = length === undefined ? reader.len : reader.pos + length, message = new $root.ExportResponse();
while (reader.pos < end) {
let tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
if (!(message.resourceList && message.resourceList.length))
message.resourceList = [];
message.resourceList.push($root.ExportResource.decode(reader, reader.uint32()));
break;
}
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
ExportResponse.toObject = function toObject(message, options) {
if (!options)
options = {};
let object = {};
if (options.arrays || options.defaults)
object.resourceList = [];
if (message.resourceList && message.resourceList.length) {
object.resourceList = [];
for (let j = 0; j < message.resourceList.length; ++j)
object.resourceList[j] = $root.ExportResource.toObject(message.resourceList[j], options);
}
return object;
};
return ExportResponse;
})();
const ExportResource = $root.ExportResource = (() => {
function ExportResource(properties) {
if (properties)
for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
ExportResource.prototype.type = "";
ExportResource.prototype.uid = "";
ExportResource.prototype.periodical = null;
ExportResource.prototype.thesis = null;
ExportResource.prototype.conference = null;
ExportResource.prototype.patent = null;
ExportResource.prototype.standard = null;
ExportResource.prototype.nstr = null;
ExportResource.prototype.cstad = null;
ExportResource.decode = function decode(reader, length) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
let end = length === undefined ? reader.len : reader.pos + length, message = new $root.ExportResource();
while (reader.pos < end) {
let tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
message.type = reader.string();
break;
}
case 3: {
message.uid = reader.string();
break;
}
case 101: {
message.periodical = $root.Periodical.decode(reader, reader.uint32());
break;
}
case 102: {
message.thesis = $root.Thesis.decode(reader, reader.uint32());
break;
}
case 104: {
message.conference = $root.Conference.decode(reader, reader.uint32());
break;
}
case 119: {
message.patent = $root.Patent.decode(reader, reader.uint32());
break;
}
case 120: {
message.standard = $root.Standard.decode(reader, reader.uint32());
break;
}
case 121: {
message.nstr = $root.Nstr.decode(reader, reader.uint32());
break;
}
case 122: {
message.cstad = $root.Cstad.decode(reader, reader.uint32());
break;
}
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
ExportResource.toObject = function toObject(message, options) {