-
Notifications
You must be signed in to change notification settings - Fork 0
Firebase storage changes #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,23 @@ | |
| <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> | ||
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"> | ||
|
|
||
| <!-- Firebase SDKs --> | ||
| <script src="https://www.gstatic.com/firebasejs/9.22.2/firebase-app-compat.js"></script> | ||
| <script src="https://www.gstatic.com/firebasejs/9.22.2/firebase-storage-compat.js"></script> | ||
| <script> | ||
| const firebaseConfig = { | ||
| apiKey: "AIzaSyBIuTnTru0iILMqOyKRzu2mZtIBnxEhdug", | ||
| authDomain: "fir-test-d319a.firebaseapp.com", | ||
| projectId: "fir-test-d319a", | ||
| storageBucket: "fir-test-d319a.firebasestorage.app", | ||
| messagingSenderId: "913686234554", | ||
| appId: "1:913686234554:android:0b20d5d7e441a710" | ||
| }; | ||
| firebase.initializeApp(firebaseConfig); | ||
| const storage = firebase.storage(); | ||
| </script> | ||
|
Comment on lines
+16
to
+26
|
||
|
|
||
|
|
||
| <style> | ||
| /* Override Bootstrap primary color to match navbar color */ | ||
| :root { | ||
|
|
@@ -79,10 +96,18 @@ <h6 class="fw-bold">AR Card</h6> | |
| <option value="custom">Custom</option> | ||
| </select> | ||
| </div> | ||
|
|
||
| <div class="mb-3" id="customImageUrlInput" style="display: none;"> | ||
| <label for="customImageUrl" class="form-label">Custom Image URL</label> | ||
| <input type="text" class="form-control" id="customImageUrl" placeholder="Enter image URL"> | ||
| <label style="display: none;" for="customImageUrl" class="form-label">URL</label> | ||
| <input style="display: none;" type="text" class="form-control" id="customImageUrl" placeholder="Enter image URL"> | ||
|
|
||
| <label for="customImageFile" class="form-label">Image</label> | ||
| <div style="display: flex; align-items: center;"> | ||
| <input type="file" class="form-control" id="customImageFile" accept="image/*" onchange="uploadImage()"> | ||
| <i id="loadingIcon" class="fas fa-spinner fa-spin" style="display: none; margin-left: 10px;"></i> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="mb-3"> | ||
| <label for="cardTopInput" class="form-label">Top Text</label> | ||
| <input type="text" class="form-control" id="cardTopInput" placeholder="Enter top text"> | ||
|
|
@@ -140,6 +165,47 @@ <h5 class="modal-title">Your Custom Card Link</h5> | |
| <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script> | ||
| <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script> | ||
| <script> | ||
| function uploadImage() { | ||
| const fileInput = document.getElementById('customImageFile'); | ||
| const file = fileInput.files[0]; | ||
| const generateCardButton = document.querySelector('.btn-primary'); | ||
| const loadingIcon = document.getElementById('loadingIcon'); | ||
| if (!file) { | ||
|
Comment on lines
+171
to
+173
|
||
| alert('Please select an image file to upload.'); | ||
| return; | ||
| } | ||
|
Comment on lines
+168
to
+176
|
||
|
|
||
| generateCardButton.disabled = true; // Disable the button | ||
| loadingIcon.style.display = 'inline-block'; // Show loading icon | ||
|
|
||
| const storageRef = storage.ref('images/' + file.name); | ||
| const uploadTask = storageRef.put(file); | ||
|
Comment on lines
+181
to
+182
|
||
|
|
||
| uploadTask.on('state_changed', | ||
| (snapshot) => { | ||
| // Observe state change events such as progress, pause, and resume | ||
| const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100; | ||
| console.log('Upload is ' + progress + '% done'); | ||
| }, | ||
| (error) => { | ||
| // Handle unsuccessful uploads | ||
| console.error('Upload failed:', error); | ||
| alert('Failed to upload image.'); | ||
| generateCardButton.disabled = false; // Re-enable the button on failure | ||
| loadingIcon.style.display = 'none'; // Hide loading icon | ||
| }, | ||
| () => { | ||
| // Handle successful uploads on complete | ||
| uploadTask.snapshot.ref.getDownloadURL().then((downloadURL) => { | ||
| console.log('File available at', downloadURL); | ||
| document.getElementById('customImageUrl').value = downloadURL; | ||
| generateCardButton.disabled = false; // Re-enable the button on success | ||
| loadingIcon.style.display = 'none'; // Hide loading icon | ||
| }); | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| function toggleCustomImageInput() { | ||
| const cardImageInput = document.getElementById('cardImageInput'); | ||
| const customImageUrlInput = document.getElementById('customImageUrlInput'); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -702,7 +702,7 @@ PlayerSettings: | |||||
| webGLDebugSymbols: 0 | ||||||
| webGLEmscriptenArgs: | ||||||
| webGLModulesDirectory: | ||||||
| webGLTemplate: PROJECT:XRCardTemplate | ||||||
| webGLTemplate: APPLICATION:Minimal | ||||||
|
||||||
| webGLTemplate: APPLICATION:Minimal | |
| webGLTemplate: PROJECT:XRCardTemplate |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!114 &1 | ||
| MonoBehaviour: | ||
| m_ObjectHideFlags: 61 | ||
| m_CorrespondingSourceObject: {fileID: 0} | ||
| m_PrefabInstance: {fileID: 0} | ||
| m_PrefabAsset: {fileID: 0} | ||
| m_GameObject: {fileID: 0} | ||
| m_Enabled: 1 | ||
| m_EditorHideFlags: 0 | ||
| m_Script: {fileID: 11500000, guid: a287be6c49135cd4f9b2b8666c39d999, type: 3} | ||
| m_Name: | ||
| m_EditorClassIdentifier: | ||
| assetDefaultFramerate: 60 | ||
| m_DefaultFrameRate: 60 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoding the Origin header to http://localhost will fail CORS checks when deployed to any other host and, in WebGL, browsers ignore attempts to override the Origin header. Remove this header override and rely on proper CORS on the image host (Firebase Storage download URLs already return appropriate CORS headers).