-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample-get-nftdriveData.html
More file actions
1364 lines (1117 loc) · 57.1 KB
/
Copy pathsample-get-nftdriveData.html
File metadata and controls
1364 lines (1117 loc) · 57.1 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NFTDriveData</title>
<script src="bundle.min.js"></script>
<script src="aes.js"></script>
</head>
<head>
<style>
.accordion {
background-color: #eee;
cursor: pointer;
padding: 10px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-weight: bold;
margin-top: 5px;
}
.accordion.active,
.accordion:hover {
background-color: #ccc;
}
.panel {
padding: 10px;
display: none;
background-color: white;
border: 1px solid #ccc;
white-space: pre-wrap;
word-wrap: break-word;
}
.loader {
border: 8px solid #f3f3f3;
border-top: 8px solid #3f51b5;
border-radius: 50%;
width: 48px;
height: 48px;
animation: spin 1s linear infinite;
margin: 0 auto 10px auto;
}
.progress-container {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 90%;
max-width: 600px;
padding: 20px;
background-color: #f8f9fa;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
display: flex;
flex-direction: column;
align-items: center;
z-index: 1000;
}
.progress-bar-wrapper {
width: 100%;
height: 30px;
background-color: #e0e0e0;
border-radius: 15px;
overflow: hidden;
position: relative;
margin: 10px 0;
}
.progress-bar {
height: 100%;
background: linear-gradient(90deg, #3f51b5, #5c6bc0);
border-radius: 15px;
transition: width 0.3s ease;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: bold;
font-size: 14px;
}
.progress-message {
text-align: center;
margin-top: 10px;
color: #333;
font-size: 14px;
}
.progress-details {
text-align: center;
margin-top: 5px;
color: #666;
font-size: 12px;
}
#progressContainer {
display: none;
}
#progressContainer.show {
display: block;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.preview {
margin: 20px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 8px;
min-height: 150px;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
max-width: calc(100% - 40px);
max-height: calc(100vh - 100px);
overflow: auto;
}
.preview img {
max-width: 100%;
max-height: calc(100vh - 150px);
height: auto;
width: auto;
display: block;
object-fit: contain;
cursor: zoom-in;
transition: transform 0.2s ease;
}
.preview img.zoomed {
cursor: zoom-out;
}
.zoom-container {
position: relative;
display: inline-block;
overflow: auto;
max-width: 100%;
max-height: calc(100vh - 150px);
user-select: none;
}
.zoom-container img {
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
.preview video,
.preview audio {
max-width: 100%;
display: block;
}
.preview iframe {
max-width: 100%;
display: block;
}
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
h1 {
text-align: center;
margin-top: 20px;
}
</style>
</head>
<body>
<div>
<!-- <h1>NFTDriveData</h1> -->
<div id="progressContainer" class="progress-container">
<div class="loader"></div>
<div class="progress-bar-wrapper">
<div id="progressBar" class="progress-bar" style="width: 0%">0%</div>
</div>
<div id="progressMessage" class="progress-message">読み込み中...</div>
<div id="progressDetails" class="progress-details"></div>
</div>
<div id="preview" class="preview"></div>
<div id="result"></div>
<div id="accordion-container"></div>
</div>
<script>
const NODELIST = {
mainnet: [
"https://sn1.msus-symbol.com:3001",
"https://ichigo-node.xyz:3001",
"https://0-0-0-0.symbol-nodes.jp:3001",
"https://01.symbol-node.com:3001",
"https://03.symbol-node.com:3001",
"https://symbol-node.teritaris.net:3001",
"https://symbol-no:3001"
],
testnet: [
"https://201-sai-dual.symboltest.net:3001",
"https://testnet1.symbol-mikun.net:3001",
"https://testnet2.symbol-mikun.net:3001",
"https://sym-test-03.opening-line.jp:3001",
"https://001-sai-dual.symboltest.net:3001",
"https://vmi831828.contaboserver.net:3001",
"https://symbol-azure.0009.co:3001"
]
}
function shuffleArray(array) {
const shuffled = [...array]; // コピーを作成
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
// 要素を交換
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
return shuffled;
}
// アドレスからネットワークを判定する関数
function getNetworkFromAddress(address) {
if (!address || address.length === 0) return 'mainnet';
const firstChar = address.charAt(0).toUpperCase();
return firstChar === 'N' ? 'mainnet' : 'testnet';
}
// ネットワークに応じたフェッチャーを初期化
let fetcher;
function initializeFetcher(address) {
const network = getNetworkFromAddress(address);
shuffleNode = shuffleArray(NODELIST[network]);
fetcher = new SymbolTransactionFetcher(shuffleNode);
}
// URLのGETパラメータからaddressを取得する関数
function getAddressFromURL() {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get('address');
}
// NFTDriveDataを取得して表示する処理
function fetchAndDisplayNFTDriveData(address) {
if (!address) {
console.error("アドレスが指定されていません");
return;
}
initializeFetcher(address);
// プログレスバーを表示
const progressContainer = document.getElementById('progressContainer');
const progressBar = document.getElementById('progressBar');
const progressMessage = document.getElementById('progressMessage');
const progressDetails = document.getElementById('progressDetails');
const preview = document.getElementById('preview');
progressContainer.classList.add('show');
preview.innerHTML = '';
// プログレス監視タイマー
let progressTimer = setInterval(() => {
const progress = fetcher.getProgress();
// プログレスバーを更新
progressBar.style.width = progress.percentage + '%';
progressBar.textContent = progress.percentage + '%';
progressMessage.textContent = progress.message || '読み込み中...';
if (progress.details && progress.details.total > 0) {
progressDetails.textContent = `${progress.details.fetched} / ${progress.details.total} 件取得済み`;
}
}, 100);
fetcher.fetchAllAggregatesStable(address, {
indexNodeIndex: 0,
indexPageSize: 100,
indexTypes :[16705], // 必要なら [16705, 16961]
concurrency:2,
retries:3
}).then(async (result) => {
await fetcher.getNFTDriveData(result, { debugger: true })
.then(async (sortedAggTxes) => {
// データ表示
renderAccordionFromObject(sortedAggTxes);
base64Preview(sortedAggTxes.header, sortedAggTxes.data, document.getElementById('preview'));
// プログレス完了
clearInterval(progressTimer);
setTimeout(() => {
progressContainer.classList.remove('show');
}, 500);
// デバッグモード時に欠損トランザクション分析を表示
if (sortedAggTxes.debugInfo.lostCount > 0) {
sortedAggTxes.debugInfo.aggregateTransactions = result;
displayLostTransactionAnalysis(sortedAggTxes.debugInfo);
}
})
.catch(err => {
console.error("NFTDriveData生成エラー:", err);
clearInterval(progressTimer);
progressContainer.classList.remove('show');
preview.innerHTML = '<p style="color: red;">データ取得エラーが発生しました</p>';
});
}).catch(err => {
console.error("安定版アグリゲートトランザクション取得エラー:", err);
clearInterval(progressTimer);
progressContainer.classList.remove('show');
preview.innerHTML = '<p style="color: red;">トランザクション取得エラーが発生しました</p>';
});
}
// ページロード時にGETパラメータをチェック
window.addEventListener('DOMContentLoaded', function () {
let addressFromURL = getAddressFromURL();
// GETパラメータがない場合、プロンプトで入力
if (!addressFromURL) {
addressFromURL = prompt("NFTDriveデータを取得するアドレスを入力してください:");
if (!addressFromURL) {
document.getElementById('preview').innerHTML = `<p style="color: blue;">アドレスが入力されませんでした。</p>`;
return;
}
}
// 自動的にデータ取得を実行
fetchAndDisplayNFTDriveData(addressFromURL);
});
// アコーディオンの表示
function renderAccordionFromObject(obj, containerId = 'accordion-container') {
const container = document.getElementById(containerId);
container.innerHTML = '';
Object.keys(obj).forEach(key => {
// アコーディオンボタン
const btn = document.createElement('button');
btn.className = 'accordion';
btn.textContent = key;
// コンテンツパネル
const panel = document.createElement('div');
panel.className = 'panel';
panel.textContent = typeof obj[key] === 'object'
? JSON.stringify(obj[key], null, 2)
: String(obj[key]);
// トグル処理
btn.addEventListener('click', () => {
panel.style.display = (panel.style.display === 'block') ? 'none' : 'block';
btn.classList.toggle('active');
});
container.appendChild(btn);
container.appendChild(panel);
});
}
let TextDecoderClass;
// Node.js 環境では `util.TextDecoder` を使用
if (typeof window === 'undefined') {
const { TextDecoder } = require('util');
TextDecoderClass = TextDecoder;
} else {
TextDecoderClass = TextDecoder;
}
// 16進数メッセージをデコードする関数
function decodeHexMessage(hex) {
if (!hex || hex.length < 2) return '';
const bytes = new Uint8Array(hex.match(/.{1,2}/g).map(b => parseInt(b, 16)));
const decoder = new TextDecoderClass('utf-8');
// 先頭1バイトはメッセージタイプなので除外
let decoded = decoder.decode(bytes.subarray(1))
// 文字列の最初と最後の空白を削除
return decoded;
}
// Base64プレビュー関数
function base64Preview(header, base64Data, containerElement) {
// デバッグ情報をログ出力
console.log("=== base64Preview デバッグ情報 ===");
console.log("ヘッダー:", header);
console.log("Base64データ長:", base64Data.length);
console.log("Base64データ先頭200文字:", base64Data.substring(0, 200));
console.log("Base64データ末尾200文字:", base64Data.substring(Math.max(0, base64Data.length - 200)));
// 暗号化データかどうかを判定(Salt付きBase64の特徴:U2FsdGVkX1で始まる)
const isEncrypted = base64Data.startsWith('U2FsdGVkX1');
if (isEncrypted) {
console.log("暗号化データが検出されました。パスワードを入力してください。");
handleEncryptedData(base64Data, containerElement);
return;
}
// JSON Base64の判定と処理
if (base64Data.startsWith('eyJ')) {
try {
const jsonString = atob(base64Data);
const jsonData = JSON.parse(jsonString);
const container = document.createElement("div");
container.style.padding = "15px";
container.style.backgroundColor = "#f5f5f5";
container.style.borderRadius = "5px";
container.style.whiteSpace = "pre-wrap";
container.style.wordWrap = "break-word";
container.textContent = JSON.stringify(jsonData, null, 2);
containerElement.appendChild(container);
return;
} catch (e) {
console.error("JSON パース失敗:", e.message);
}
}
// 通常のBase64処理
const match = base64Data.match(/^data:([^;]+);base64,(.*)$/);
if (!match) {
containerElement.innerHTML = `<p style="color: red;">エラー:有効なBase64データが見つかりません<br/>
データ先頭: ${base64Data.substring(0, 100)}</p>`;
return;
}
renderPreview(match[1], match[2], containerElement);
}
// 暗号化データを処理する関数
function handleEncryptedData(encryptedBase64, containerElement) {
const password = prompt("このNFTDriveデータは暗号化されています。\nパスワードを入力してください:");
if (password === null) {
containerElement.innerHTML = `<p style="color: blue;">データの復号化がキャンセルされました。</p>`;
return;
}
try {
// CryptoJS.AES.decryptを使用して復号化
const decrypted = CryptoJS.AES.decrypt(encryptedBase64, password);
const decryptedString = decrypted.toString(CryptoJS.enc.Utf8);
if (!decryptedString) {
throw new Error("復号化に失敗しました。パスワードが正しくない可能性があります。");
}
// 復号化されたデータがBase64形式かどうかを判定
const match = decryptedString.match(/^data:([^;]+);base64,(.*)$/);
if (!match) {
// 復号化されたデータがそのままBase64の場合
renderPreview("application/octet-stream", decryptedString, containerElement);
} else {
// MIMEタイプ付きの場合
renderPreview(match[1], match[2], containerElement);
}
} catch (error) {
console.error("復号化エラー:", error.message);
containerElement.innerHTML = `<p style="color: red;">エラー:${error.message}</p>`;
}
}
// プレビュー表示の共通処理
function renderPreview(mimeType, base64Data, containerElement) {
let base64 = base64Data;
// Base64が空の場合
if (!base64 || base64.length === 0) {
console.error("Base64データが空です");
containerElement.innerHTML = `<p style="color: red;">エラー:Base64データが空です</p>`;
return;
}
console.log("renderPreview前:", "長さ", base64.length, "% 4 =", base64.length % 4);
let binaryData;
try {
console.log("atob実行前:", "長さ", base64.length, "末尾", base64.substring(base64.length - 5));
binaryData = atob(base64);
console.log("✓ atob成功:", "バイナリ長", binaryData.length);
} catch (e) {
console.error("❌ Base64 decode に失敗:", e.message);
console.error(" Base64データ長:", base64.length);
console.error(" 長さ % 4:", base64.length % 4);
console.error(" 末尾20文字:", base64.substring(base64.length - 20));
console.error(" 先頭100文字:", base64.substring(0, 100));
containerElement.innerHTML = `<p style="color: red;">エラー:Base64デコード失敗<br/>
形式: ${mimeType}<br/>
データ長: ${base64.length}<br/>
詳細: ${e.message}</p>`;
return;
}
// バイナリデータが空の場合
if (!binaryData || binaryData.length === 0) {
console.error("デコード後のバイナリデータが空です");
containerElement.innerHTML = `<p style="color: red;">エラー:デコード後のデータが空です</p>`;
return;
}
// Base64データをUint8Arrayに変換
const byteArray = new Uint8Array(binaryData.length);
for (let i = 0; i < binaryData.length; i++) {
byteArray[i] = binaryData.charCodeAt(i);
}
// // ★ WAV ファイルの場合、メタデータを解析
// if (mimeType === 'audio/wav') {
// const wavMetadata = analyzeWAVMetadata(byteArray);
// displayWAVAnalysis(wavMetadata);
// }
const blob = new Blob([byteArray], { type: mimeType });
const blobURL = URL.createObjectURL(blob);
console.log("✓ MIME:", mimeType, "データ長:", byteArray.length);
containerElement.innerHTML = "";
let element;
switch (mimeType) {
case "image/png":
case "image/jpeg":
case "image/gif":
case "image/webp":
const zoomContainer = document.createElement("div");
zoomContainer.className = "zoom-container";
element = document.createElement("img");
element.src = blobURL;
element.alt = "画像プレビュー";
element.style.maxWidth = "100%";
element.style.maxHeight = "calc(100vh - 150px)";
element.style.height = "auto";
element.style.width = "auto";
element.style.display = "block";
element.style.objectFit = "contain";
element.style.userSelect = "none";
element.style.webkitUserSelect = "none";
element.draggable = false;
let scale = 1;
const maxScale = 5; // 最大5倍までズーム
let isDragging = false;
let startX = 0;
let startY = 0;
let scrollLeft = 0;
let scrollTop = 0;
// マウスホイールでズーム
element.addEventListener('wheel', (e) => {
if (!e.ctrlKey) {
e.preventDefault();
const delta = e.deltaY > 0 ? -0.1 : 0.1;
scale = Math.max(1, Math.min(maxScale, scale + delta));
element.style.transform = `scale(${scale})`;
element.style.transformOrigin = "center center";
if (scale > 1) {
element.classList.add('zoomed');
zoomContainer.style.overflow = "auto";
} else {
element.classList.remove('zoomed');
zoomContainer.style.overflow = "auto";
}
}
}, { passive: false });
// ダブルクリックでズームリセット
element.addEventListener('dblclick', () => {
scale = 1;
element.style.transform = `scale(${scale})`;
element.classList.remove('zoomed');
zoomContainer.scrollLeft = 0;
zoomContainer.scrollTop = 0;
});
// マウスダウンでドラッグ開始
element.addEventListener('mousedown', (e) => {
if (scale > 1 && e.button === 0) { // 左クリックのみ
isDragging = true;
startX = e.clientX;
startY = e.clientY;
scrollLeft = zoomContainer.scrollLeft;
scrollTop = zoomContainer.scrollTop;
element.style.cursor = "grabbing";
e.preventDefault();
}
});
// マウスムーブでスクロール
const handleMouseMove = (e) => {
if (!isDragging) return;
const x = e.clientX;
const y = e.clientY;
const walkX = (x - startX) * 1.5; // スクロール感度調整
const walkY = (y - startY) * 1.5;
zoomContainer.scrollLeft = scrollLeft - walkX;
zoomContainer.scrollTop = scrollTop - walkY;
};
// マウスアップでドラッグ終了
const handleMouseUp = () => {
isDragging = false;
element.style.cursor = scale > 1 ? "grab" : "zoom-in";
};
// グローバルリスナーを登録
document.addEventListener('mousemove', handleMouseMove, false);
document.addEventListener('mouseup', handleMouseUp, false);
// ズームされていない時はデフォルトカーソル
element.addEventListener('mouseover', () => {
if (scale > 1) {
element.style.cursor = "grab";
} else {
element.style.cursor = "zoom-in";
}
});
element.addEventListener('mouseleave', () => {
if (!isDragging) {
element.style.cursor = "default";
}
});
// ドラッグ中のテキスト選択を防止
element.addEventListener('selectstart', (e) => {
if (isDragging) {
e.preventDefault();
}
});
// タッチデバイス用ピンチズーム
let lastDistance = 0;
element.addEventListener('touchmove', (e) => {
if (e.touches.length === 2) {
e.preventDefault();
const touch1 = e.touches[0];
const touch2 = e.touches[1];
const distance = Math.hypot(
touch2.clientX - touch1.clientX,
touch2.clientY - touch1.clientY
);
if (lastDistance > 0) {
const ratio = distance / lastDistance;
scale = Math.max(1, Math.min(maxScale, scale * ratio));
element.style.transform = `scale(${scale})`;
element.style.transformOrigin = "center center";
if (scale > 1) {
element.classList.add('zoomed');
} else {
element.classList.remove('zoomed');
}
}
lastDistance = distance;
}
}, { passive: false });
element.addEventListener('touchend', () => {
lastDistance = 0;
});
zoomContainer.appendChild(element);
containerElement.appendChild(zoomContainer);
return;
case "video/mp4":
case "video/webm":
element = document.createElement("video");
element.src = blobURL;
element.controls = true;
element.style.maxWidth = "100%";
element.style.height = "auto";
element.style.display = "block";
break;
case "audio/mpeg":
case "audio/wav":
case "audio/ogg":
element = document.createElement("audio");
element.src = blobURL;
element.controls = true;
element.style.maxWidth = "100%";
element.style.display = "block";
break;
case "application/pdf":
element = document.createElement("iframe");
element.src = blobURL;
element.style.width = "100%";
element.style.height = "100vh";
element.style.minHeight = "100vh";
element.style.border = "none";
element.style.display = "block";
element.onload = function () {
// iframeが読み込まれたら高さを調整
try {
const iframeDoc = element.contentDocument || element.contentWindow.document;
if (iframeDoc && iframeDoc.body) {
const scrollHeight = iframeDoc.body.scrollHeight;
element.style.height = (scrollHeight + 20) + "px";
}
} catch (e) {
console.warn("iframeの高さ調整に失敗(クロスオリジンの可能性):", e);
element.style.height = "100vh";
}
};
break;
case "text/plain":
// ★ text/plainの場合、まずBase64をテキストにデコード
let plainTextContent = '';
try {
// Base64 → バイナリに変換
const binaryString = atob(base64Data);
// ★ バイナリ → UTF-8テキストに変換(文字化け対策)
const uint8Array = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++) {
uint8Array[i] = binaryString.charCodeAt(i);
}
const decoder = new TextDecoder('utf-8');
plainTextContent = decoder.decode(uint8Array);
console.log("✓ Base64デコード成功:", plainTextContent.substring(0, 100));
} catch (e) {
console.error("Base64デコード失敗:", e.message);
element = document.createElement("p");
element.style.color = "red";
element.textContent = `エラー:Base64デコード失敗 - ${e.message}`;
containerElement.appendChild(element);
return;
}
// デコード後のテキストがJSONかどうかを判定
try {
const jsonData = JSON.parse(plainTextContent);
// JSONパース成功 → JSON表示
element = document.createElement("div");
element.style.padding = "15px";
element.style.backgroundColor = "#f5f5f5";
element.style.borderRadius = "5px";
element.style.whiteSpace = "pre-wrap";
element.style.wordWrap = "break-word";
element.style.fontFamily = "monospace";
element.style.fontSize = "12px";
element.style.maxHeight = "80vh";
element.style.overflow = "auto";
element.style.border = "1px solid #ddd";
element.textContent = JSON.stringify(jsonData, null, 2);
console.log("✓ JSON形式で表示します");
} catch (e) {
// JSONパース失敗 → プレーンテキスト表示
element = document.createElement("div");
element.style.padding = "15px";
element.style.backgroundColor = "#f9f9f9";
element.style.borderRadius = "5px";
element.style.whiteSpace = "pre-wrap";
element.style.wordWrap = "break-word";
element.style.fontFamily = "monospace";
element.style.fontSize = "12px";
element.style.maxHeight = "80vh";
element.style.overflow = "auto";
element.style.border = "1px solid #ddd";
element.textContent = plainTextContent;
console.log("✓ プレーンテキスト形式で表示します");
}
break;
case "text/html":
element = document.createElement("iframe");
element.src = blobURL;
element.style.width = "100%";
element.style.height = "100vh";
// element.style.minHeight = "100vh";
element.style.border = "none";
element.style.display = "block";
break;
default:
element = document.createElement("p");
element.textContent = `対応していないMIMEタイプ: ${mimeType}`;
break;
}
containerElement.appendChild(element);
}
// Base64の不正文字を除去し、4の倍数にする
function sanitizeBase64(base64) {
// 前後の空白を削除
// base64 = base64.trim();
// base64 = base64.replace(/[\s\n\r\t]/g, '');
// base64 = base64.replace(/=+$/, '');
// console.log("✓ sanitizeBase64 処理後:");
// console.log(" 処理後データ長:", base64.length);
// console.log(" 長さ % 4:", base64.length % 4);
// console.log(" パディング:", (base64.match(/=+$/)?.[0] || 'なし'));
// console.log(" 末尾10文字:", base64.substring(base64.length - 10));
return base64;
}
// デバッグ用:データ解析ツール
async function analyzeNFTDriveData(address) {
initializeFetcher(address);
try {
const allTxs = await fetcher.getAllTransactionsAggregate(address);
const result = await fetcher.fetchTransactionsByHashes(allTxs);
// 解析実行
const analysis = fetcher.analyzNFTDriveData(result);
console.log("=== NFTDriveData 詳細解析 ===");
console.log(JSON.stringify(analysis, null, 2));
// HTMLに詳細結果を表示
document.getElementById('result').innerHTML = `<pre style="background: #f0f0f0; padding: 10px; overflow: auto; max-height: 400px;">${JSON.stringify(analysis, null, 2)}</pre>`;
return analysis;
} catch (error) {
console.error("解析エラー:", error);
}
}
function displayTransactionAnalysis(debugInfo) {
const { transactionContinuity } = debugInfo;
if (!transactionContinuity) return;
const {
transactionArrayCount,
messageNumbers,
missingMessages,
messageRange,
isComplete,
completenessPercentage
} = transactionContinuity;
let html = `<div style="background: ${isComplete ? '#d4edda' : '#fff3cd'}; border: 2px solid ${isComplete ? '#28a745' : '#ff9800'}; padding: 15px; margin: 10px 0; border-radius: 5px;">`;
html += `<h3 style="color: ${isComplete ? '#155724' : '#ff6600'}; margin-top: 0;">${isComplete ? '✓' : '⚠'} トランザクション構造分析</h3>`;
html += `<table style="width: 100%; border-collapse: collapse; margin-bottom: 15px;">`;
html += `<tr style="background: ${isComplete ? '#c3e6cb' : '#ffe0b2'};">
<th style="padding: 8px; border: 1px solid #ccc; text-align: left;">項目</th>
<th style="padding: 8px; border: 1px solid #ccc; text-align: left;">値</th>
</tr>`;
html += `<tr>
<td style="padding: 8px; border: 1px solid #ccc;"><strong>Tx配列インデックス範囲</strong></td>
<td style="padding: 8px; border: 1px solid #ccc;">0 ~ ${transactionArrayCount - 1} (合計${transactionArrayCount}個)</td>
</tr>`;
html += `<tr>
<td style="padding: 8px; border: 1px solid #ccc;"><strong>メッセージ番号範囲</strong></td>
<td style="padding: 8px; border: 1px solid #ccc;">${messageRange.min} ~ ${messageRange.max}</td>
</tr>`;
const expectedMsg = messageRange.max - messageRange.min + 1;
html += `<tr>
<td style="padding: 8px; border: 1px solid #ccc;"><strong>期待メッセージ数</strong></td>
<td style="padding: 8px; border: 1px solid #ccc;">${expectedMsg}個</td>
</tr>`;
html += `<tr>
<td style="padding: 8px; border: 1px solid #ccc;"><strong>実取得メッセージ数</strong></td>
<td style="padding: 8px; border: 1px solid #ccc;"><strong>${messageNumbers.length}個</strong></td>
</tr>`;
html += `<tr style="background: ${isComplete ? '#c3e6cb' : '#ffccbc'};">
<td style="padding: 8px; border: 1px solid #ccc;"><strong>欠損メッセージ数</strong></td>
<td style="padding: 8px; border: 1px solid #ccc;"><strong style="color: ${isComplete ? 'green' : 'red'}">${missingMessages.length}個</strong></td>
</tr>`;
html += `<tr>
<td style="padding: 8px; border: 1px solid #ccc;"><strong>完全性</strong></td>
<td style="padding: 8px; border: 1px solid #ccc;"><strong>${completenessPercentage}%</strong></td>
</tr>`;
html += `</table>`;
if (!isComplete && missingMessages.length > 0) {
html += `<h4 style="color: red;">📍 欠損メッセージ番号:</h4>`;
html += `<p style="background: #fff; padding: 10px; border-radius: 3px; font-family: monospace; word-break: break-all; border: 1px solid #ccc;">`;
html += missingMessages.join(', ');
html += `</p>`;
html += `<p style="font-size: 12px; color: #666;">※ これらのメッセージ番号がチェーンから欠損しています</p>`;
} else {
html += `<p style="color: green; font-weight: bold;">✓ すべてのメッセージが揃っています</p>`;
}
html += `</div>`;
document.getElementById('debugInfo').innerHTML += html;
}
// 欠損検出の検証結果を表示
function displayVerificationResult(verification) {
let html = `<div style="background: #fff3cd; border: 2px solid #ffc107; padding: 15px; margin: 10px 0; border-radius: 5px;">`;
html += `<h4>欠損検出の検証</h4>`;
html += `<p>状態: <strong style="color: ${verification.isValid ? 'green' : 'red'}">${verification.isValid ? '✓ 正常' : '✗ 異常'}</strong></p>`;
if (verification.errors.length > 0) {
html += `<p style="color: red;">エラー:</p><ul>`;
verification.errors.forEach(err => {
html += `<li>${err}</li>`;
});
html += `</ul>`;
}
html += `<p>範囲: ${verification.details.expectedRange.min} ~ ${verification.details.expectedRange.max} (期待${verification.details.expectedRange.count}個)</p>`;
html += `<p>実取得: ${verification.details.totalExtracted}個</p>`;
html += `<p>欠損: ${verification.details.lostCount}個</p>`;
html += `</div>`;
document.getElementById('debugInfo').innerHTML += html;
}
//WAB調査