jclyo1 commited on
Commit
958d291
1 Parent(s): 4e86a3a
Files changed (1) hide show
  1. static/index.html +1 -472
static/index.html CHANGED
@@ -393,476 +393,5 @@
393
  </div>
394
  </body>
395
 
396
- <script>
397
- const generateTab = document.querySelector("#generateTab");
398
- const verifyTab = document.querySelector("#verifyTab");
399
- const displayVerify = document.querySelectorAll(".display-verify");
400
- const displayGenerate = document.querySelectorAll(".display-generate");
401
- const uploadForm = document.querySelector(".verify-upload-form");
402
- const imageGenForm = document.querySelector(".image-gen-form");
403
- const imagePrompt = document.getElementById("prompt");
404
- const model = document.getElementById("model");
405
- const generateTerms = document.getElementById("generate-terms");
406
- const generateButton = document.getElementById("generate-button");
407
-
408
- const fileUpload = document.getElementById("fileUpload");
409
- const verifyButton = document.getElementById("verify-button");
410
- const verifyTerms = document.getElementById("verify-terms");
411
-
412
- const generateImageContainer = document.querySelector(
413
- ".display-generate .image-container"
414
- );
415
- const generateActionMenu = document.querySelector(".action-menu");
416
- const verifyImageContainer = document.querySelector(
417
- ".display-verify .image-container"
418
- );
419
- const uploadedImageContainer = document.querySelector("#original-image");
420
- const downloadButton = document.getElementById("download-button");
421
- const verifyResultDescription = document.getElementById(
422
- "verifyResultDescription"
423
- );
424
- const verificationOutput = document.getElementById("verification-output");
425
- const certificateList = document.getElementById("certificate-list");
426
- const outputContainer = document.querySelector(".output-container");
427
- const contentCredentialsIcon = document.getElementById(
428
- "content-crendentials-icon"
429
- );
430
- const digitalWatermarkIcon = document.getElementById(
431
- "digital-watermark-icon"
432
- );
433
-
434
- var certificates = [];
435
-
436
- [imagePrompt, model, generateTerms].forEach((item) => {
437
- item.addEventListener("change", async (event) => {
438
- setGenerateButtonStatus();
439
- });
440
- });
441
-
442
- const setGenerateButtonStatus = () => {
443
- if (imagePrompt.value && model.value && generateTerms.checked)
444
- generateButton.classList.add("active");
445
- else generateButton.classList.remove("active");
446
- };
447
-
448
- [fileUpload, verifyTerms].forEach((item) => {
449
- item.addEventListener("change", async (event) => {
450
- setVerifyButtonStatus();
451
- });
452
- });
453
-
454
- const setVerifyButtonStatus = () => {
455
- if (fileUpload.value && verifyTerms.checked)
456
- verifyButton.classList.add("active");
457
- else verifyButton.classList.remove("active");
458
- };
459
-
460
- generateTab.addEventListener("click", (event) => {
461
- event.target.classList.add("active");
462
- verifyTab.classList.remove("active");
463
-
464
- setGenerateElementsDisplay("block");
465
- setVerifyElementsDisplay("none");
466
- });
467
-
468
- verifyTab.addEventListener("click", (event) => {
469
- event.target.classList.add("active");
470
- generateTab.classList.remove("active");
471
-
472
- setGenerateElementsDisplay("none");
473
- setVerifyElementsDisplay("block");
474
- });
475
-
476
- document
477
- .getElementById("goto-verify-button")
478
- .addEventListener("click", (event) => {
479
- verifyTab.classList.add("active");
480
- generateTab.classList.remove("active");
481
-
482
- setVerifyElementsDisplay("block");
483
- setGenerateElementsDisplay("none");
484
- });
485
-
486
- function setGenerateElementsDisplay(displayStatus) {
487
- displayGenerate.forEach((item) => {
488
- item.style.display = displayStatus;
489
- });
490
- }
491
-
492
- function setVerifyElementsDisplay(displayStatus) {
493
- displayVerify.forEach((item) => {
494
- item.style.display = displayStatus;
495
- });
496
- }
497
-
498
- uploadForm.addEventListener("submit", (e) => {
499
- e.preventDefault();
500
- submitForm();
501
- });
502
-
503
- function submitForm() {
504
- if (!fileUpload.value || !verifyTerms.checked) return;
505
-
506
- const file = document.getElementById("fileUpload").files[0];
507
-
508
- let fileReader = new FileReader();
509
- fileReader.readAsDataURL(file);
510
- fileReader.onload = function () {
511
- document
512
- .getElementById("uploaded-image")
513
- .setAttribute("src", fileReader.result);
514
- };
515
-
516
- document.querySelector(".display-verify .error").style.display = "none";
517
- placeholder = document.querySelector(".display-verify .placeholder");
518
- spinner = document.querySelector(".display-verify .spinner");
519
- placeholder.style.display = "none";
520
-
521
- if (document.getElementById("verifyresult"))
522
- document.getElementById("verifyresult").remove(); // JCL make sure to remove the correct one
523
- spinner.style.display = "block";
524
-
525
- outputContainer.style.display = "none";
526
- document.getElementById("resultLabel").style.display = "none";
527
- uploadedImageContainer.style.display = "none";
528
-
529
- const formData = new FormData(uploadForm);
530
-
531
- // Add additional form data as needed
532
- //formData.append('additionalData', 'additionalValue');
533
-
534
- // Call function to submit form data
535
- submitFormData(formData);
536
- }
537
-
538
- function submitFormData(formData) {
539
- fetch("verify", {
540
- method: "POST",
541
- body: formData,
542
- })
543
- .then((response) => response.json())
544
- .then((data) => {
545
- console.log(data);
546
-
547
- fileUpload.value = "";
548
- setVerifyButtonStatus();
549
-
550
- if (data.contains_c2pa == "true") {
551
- contentCredentialsIcon.setAttribute("class", "check-icon");
552
- } else {
553
- contentCredentialsIcon.setAttribute("class", "x-icon");
554
- }
555
-
556
- if (data.contains_watermark == "true") {
557
- digitalWatermarkIcon.setAttribute("class", "check-icon");
558
- } else {
559
- digitalWatermarkIcon.setAttribute("class", "x-icon");
560
- }
561
-
562
- if (
563
- data.contains_c2pa == "true" &&
564
- data.contains_watermark == "true"
565
- ) {
566
- verifyResultDescription.innerHTML =
567
- "Your image contains content credentials, which are displayed below.";
568
- } else if (
569
- data.contains_c2pa == "false" &&
570
- data.contains_watermark == "true"
571
- ) {
572
- verifyResultDescription.innerHTML =
573
- "The watermark was found, but image modifications were also detected. The last untampered, signed version on file is displayed.";
574
- } else if (
575
- data.contains_c2pa == "true" &&
576
- data.contains_watermark == "false"
577
- ) {
578
- verifyResultDescription.innerHTML =
579
- "Your image contains content credentials, which are displayed below. A watermark was not detected.";
580
- } else if (
581
- data.contains_c2pa == "false" &&
582
- data.contains_watermark == "false"
583
- ) {
584
- verifyResultDescription.innerHTML =
585
- "Nothing to show: this image contains neither content credentials, nor a watermark.";
586
- }
587
-
588
- uploadedImageContainer.style.display = "flex";
589
- document.getElementById("resultLabel").style.display = "block";
590
-
591
- document.querySelector(".display-verify .spinner").style.display =
592
- "none";
593
-
594
- if (data.result_media != "n/a") {
595
- const path = "/" + data.result_media;
596
-
597
- var truepicDisplay = document.createElement("truepic-display");
598
-
599
- truepicDisplay.addEventListener(
600
- "validate",
601
- setVerificationOutputFromValidation
602
- );
603
- truepicDisplay.addEventListener(
604
- "validate",
605
- setCertificateOutputFromValidation
606
- );
607
-
608
- truepicDisplay.setAttribute("id", "verifyresult");
609
- truepicDisplay.setAttribute("active", "");
610
- var truepic = document.createElement("img");
611
- truepic.src = path;
612
-
613
- truepicDisplay.appendChild(truepic);
614
-
615
- verifyImageContainer.appendChild(truepicDisplay);
616
-
617
- outputContainer.style.display = "block";
618
- }
619
- // Handle response data
620
- })
621
- .catch((error) => {
622
- console.log(error);
623
- document.querySelector(".display-verify .error").style.display =
624
- "block";
625
-
626
- fileUpload.value = "";
627
- setVerifyButtonStatus();
628
-
629
- document.querySelector(".display-verify .spinner").style.display =
630
- "none";
631
- document.querySelector(".display-verify .placeholder").style.display =
632
- "block";
633
- // Handle errors
634
- });
635
- }
636
-
637
- const generateImage = async (text, model) => {
638
- const inferResponse = await fetch(
639
- `generate?prompt=${text}&model=${model}`
640
- );
641
- const inferJson = await inferResponse.json();
642
-
643
- return inferJson.response;
644
- };
645
-
646
- imageGenForm.addEventListener("submit", async (event) => {
647
- event.preventDefault();
648
-
649
- if (!imagePrompt.value || !model.value || !generateTerms.checked) return;
650
-
651
- placeholder = document.querySelector(".display-generate .placeholder");
652
- spinner = document.querySelector(".display-generate .spinner");
653
- generateActionMenu.style.display = "none";
654
- document.querySelector(".display-generate .error").style.display = "none";
655
-
656
- // parameters.style.display = "none";
657
-
658
- try {
659
- placeholder.style.display = "none";
660
- if (document.getElementById("genresult"))
661
- document.getElementById("genresult").remove(); // JCL make sure to remove the correct one
662
-
663
- spinner.style.display = "block";
664
-
665
- const resp = await generateImage(imagePrompt.value, model.value);
666
- const path = "/" + resp;
667
-
668
- var truepicDisplay = document.createElement("truepic-display");
669
-
670
- truepicDisplay.setAttribute("id", "genresult");
671
- truepicDisplay.setAttribute("active", "");
672
- var truepic = document.createElement("img");
673
- truepic.src = path;
674
-
675
- truepicDisplay.appendChild(truepic);
676
-
677
- spinner.style.display = "none";
678
- generateImageContainer.appendChild(truepicDisplay);
679
-
680
- downloadButton.href = path;
681
- downloadButton.download = resp;
682
-
683
- generateActionMenu.style.display = "block";
684
-
685
- /*
686
-
687
-
688
- modelParam.innerHTML = model.value;
689
- promptParam.innerHTML = textGenInput.value;
690
- parameters.style.display = "block";
691
- */
692
- } catch (err) {
693
- console.error(err);
694
- document.querySelector(".display-generate .error").style.display =
695
- "block";
696
- spinner.style.display = "none";
697
- placeholder.style.display = "block";
698
- }
699
- });
700
-
701
- function setVerificationOutputFromValidation(event) {
702
- //verificationDetails.style.display = "block";
703
- return setVerificationOutput(event.detail.manifestStore.toJSON());
704
- }
705
-
706
- function setCertificateOutputFromValidation(event) {
707
- return setCertificateOutput(event.detail.manifestStore);
708
- }
709
-
710
- function setVerificationOutput(output = null) {
711
- verificationOutput.innerHTML = "";
712
-
713
- if (!output) {
714
- return;
715
- }
716
-
717
- const viewer = new JSONViewer();
718
-
719
- verificationOutput.appendChild(viewer.getContainer());
720
-
721
- viewer.showJSON(output);
722
- }
723
-
724
- function setCertificateOutput(manifestStore = null) {
725
- const certificate = manifestStore?.activeManifest?.certificate;
726
-
727
- if (!certificate) {
728
- return;
729
- }
730
-
731
- certificates = [
732
- {
733
- der: certificate.der,
734
- name: certificate.subjectName,
735
- decoded: new x509.X509Certificate(certificate.der),
736
- },
737
- ...certificate.chain.map((certificate) => ({
738
- der: certificate.der,
739
- decoded: new x509.X509Certificate(certificate.der),
740
- })),
741
- ];
742
-
743
- certificates.forEach((certificate) => {
744
- certificate.transformed = transformCert(certificate.decoded);
745
- });
746
-
747
- console.log("certificates", certificates);
748
-
749
- certificateList.innerHTML = "";
750
-
751
- certificates.forEach((certificate, index) => {
752
- var li = document.createElement("li");
753
- if (index == 0) li.classList.add("active");
754
- li.appendChild(
755
- document.createTextNode(certificate.transformed.subjectCommonName)
756
- );
757
- li.addEventListener("click", function (e) {
758
- setCertificate(index);
759
- const lis = document.querySelectorAll("#certificate-list li");
760
-
761
- lis.forEach((element) => {
762
- element.classList.remove("active");
763
- });
764
-
765
- this.classList.add("active");
766
- });
767
-
768
- certificateList.appendChild(li);
769
- });
770
-
771
- setCertificate(0);
772
- }
773
-
774
- function transformCert(certificate) {
775
- const {
776
- issuer,
777
- subject,
778
- notAfter: expired,
779
- notBefore: issued,
780
- serialNumber,
781
- publicKey: {
782
- algorithm: {
783
- name: algorithm,
784
- modulusLength: modulus,
785
- namedCurve: namedCurve,
786
- },
787
- },
788
- } = certificate;
789
-
790
- const parsedSubject = parseCertificateValues(subject);
791
- const parsedIssuer = parseCertificateValues(issuer);
792
-
793
- return {
794
- issuerCommonName: parsedIssuer["CN"],
795
- issuerOrganizationUnit: parsedIssuer["OU"],
796
- issuerOrganization: parsedIssuer["O"],
797
- issuerCountry: parsedIssuer["C"],
798
- subjectCommonName: parsedSubject["CN"],
799
- subjectOrganizationUnit: parsedSubject["OU"],
800
- subjectOrganization: parsedSubject["O"],
801
- subjectCountry: parsedSubject["C"],
802
- issued,
803
- expired,
804
- serialNumber,
805
- algorithm,
806
- modulus,
807
- namedCurve,
808
- };
809
- }
810
-
811
- function parseCertificateValues(input) {
812
- const params = new URLSearchParams(input.replaceAll(",", "&"));
813
- const responses = {};
814
-
815
- for (const entry of params.entries()) {
816
- responses[entry[0].trim()] = entry[1];
817
- }
818
-
819
- return responses;
820
- }
821
-
822
- function setCertificate(ind) {
823
- const certificate = certificates[ind].transformed;
824
-
825
- document.querySelector(".details .issuerCommonName").innerHTML =
826
- certificate.issuerCommonName;
827
- document.querySelector(".details .issuerOrganizationUnit").innerHTML =
828
- certificate.issuerOrganizationUnit;
829
- document.querySelector(".details .issuerOrganization").innerHTML =
830
- certificate.issuerOrganization;
831
- document.querySelector(".details .issuerCountry").innerHTML =
832
- certificate.issuerCountry;
833
- document.querySelector(".details .subjectCommonName").innerHTML =
834
- certificate.subjectCommonName;
835
- document.querySelector(".details .subjectOrganizationUnit").innerHTML =
836
- certificate.subjectOrganizationUnit;
837
- document.querySelector(".details .subjectOrganization").innerHTML =
838
- certificate.subjectOrganization;
839
- document.querySelector(".details .subjectCountry").innerHTML =
840
- certificate.subjectCountry;
841
- document.querySelector(".details .issued").innerHTML = certificate.issued;
842
- document.querySelector(".details .expired").innerHTML =
843
- certificate.expired;
844
- document.querySelector(".details .serialNumber").innerHTML =
845
- certificate.serialNumber;
846
- document.querySelector(".details .algorithm").innerHTML =
847
- certificate.algorithm;
848
-
849
- /*
850
- if (certificate.modulus !== undefined) {
851
- document.querySelector(".details .modulus").innerHTML =
852
- certificate.modulus;
853
- document.querySelector("#modulusContainers").style.display = "block";
854
- } else {
855
- document.querySelector("#modulusContainers").style.display = "none";
856
- }
857
- */
858
-
859
- if (certificate.namedCurve !== undefined) {
860
- document.querySelector(".details .namedCurve").innerHTML =
861
- certificate.namedCurve;
862
- document.querySelector("#curveContainer").style.display = "block";
863
- } else {
864
- document.querySelector("#curveContainer").style.display = "none";
865
- }
866
- }
867
- </script>
868
  </html>
 
393
  </div>
394
  </body>
395
 
396
+ <script type="text/javascript" src="script.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397
  </html>