Spaces:
Sleeping
Sleeping
Commit
·
a548ebc
0
Parent(s):
Duplicate from XciD/test-static
Browse filesCo-authored-by: Adrien <[email protected]>
- .gitattributes +34 -0
- Dockerfile +9 -0
- README.md +12 -0
- main.js +29 -0
- style.css +28 -0
- www2/index.html +11 -0
- www2/requeststorageaccess.html +9 -0
- www2/scripts/index.js +51 -0
- www2/scripts/requeststorageaccess.js +7 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM node
|
2 |
+
|
3 |
+
WORKDIR /usr/app
|
4 |
+
|
5 |
+
ADD . .
|
6 |
+
|
7 |
+
RUN npm install express
|
8 |
+
|
9 |
+
CMD node main.js
|
README.md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Test Static
|
3 |
+
emoji: 🏢
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: red
|
6 |
+
sdk: docker
|
7 |
+
app_port: 3001
|
8 |
+
pinned: false
|
9 |
+
duplicated_from: XciD/test-static
|
10 |
+
---
|
11 |
+
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
main.js
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use strict'
|
2 |
+
|
3 |
+
// Define the basic imports and constants.
|
4 |
+
const express = require('express');
|
5 |
+
const app = express();
|
6 |
+
const embeddedApp = express();
|
7 |
+
const port = 3000;
|
8 |
+
const embeddedPort = 3001;
|
9 |
+
|
10 |
+
// Setup the outside app with the www folder as static content.
|
11 |
+
app.use(express.static('www'));
|
12 |
+
|
13 |
+
// Create the outside app and run it.
|
14 |
+
app.listen(port, () => {
|
15 |
+
console.log(`Open browser to http://localhost:${port}/ to begin.`);
|
16 |
+
});
|
17 |
+
|
18 |
+
// Create the embedded app with the www2 folder as static content and
|
19 |
+
// set the cookie from the embedded app in the headers on all requests.
|
20 |
+
embeddedApp.use(express.static('www2', {
|
21 |
+
setHeaders: function (res, path, stat) {
|
22 |
+
res.set('Set-Cookie', "embeddedCookie=Hello from an embedded third party cookie!;Path=/;Secure;SameSite=None");
|
23 |
+
}
|
24 |
+
}));
|
25 |
+
|
26 |
+
// Create the server and start it.
|
27 |
+
embeddedApp.listen(embeddedPort, () => {
|
28 |
+
console.log(`Embedded server now running on ${embeddedPort}...`)
|
29 |
+
});
|
style.css
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
body {
|
2 |
+
padding: 2rem;
|
3 |
+
font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
|
4 |
+
}
|
5 |
+
|
6 |
+
h1 {
|
7 |
+
font-size: 16px;
|
8 |
+
margin-top: 0;
|
9 |
+
}
|
10 |
+
|
11 |
+
p {
|
12 |
+
color: rgb(107, 114, 128);
|
13 |
+
font-size: 15px;
|
14 |
+
margin-bottom: 10px;
|
15 |
+
margin-top: 5px;
|
16 |
+
}
|
17 |
+
|
18 |
+
.card {
|
19 |
+
max-width: 620px;
|
20 |
+
margin: 0 auto;
|
21 |
+
padding: 16px;
|
22 |
+
border: 1px solid lightgray;
|
23 |
+
border-radius: 16px;
|
24 |
+
}
|
25 |
+
|
26 |
+
.card p:last-child {
|
27 |
+
margin-bottom: 0;
|
28 |
+
}
|
www2/index.html
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<head>
|
2 |
+
<title>Hello World from third party embedded URL</title>
|
3 |
+
<link rel="stylesheet" href="content/basic.css">
|
4 |
+
<script type="text/javascript" src="scripts/index.js"></script>
|
5 |
+
</head>
|
6 |
+
<body>
|
7 |
+
<h2>I am cross-domain embedded content in an iframe</h2>
|
8 |
+
<div id="cookieValue">Cookie cannot be found,
|
9 |
+
it's being rejected by the browser...</div>
|
10 |
+
<button id="requestStorageAccessButton">Click to request storage access</button>
|
11 |
+
</body>
|
www2/requeststorageaccess.html
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<head>
|
2 |
+
<title>Request Storage Access</title>
|
3 |
+
<link rel="stylesheet" href="content/basic.css">
|
4 |
+
<script type="text/javascript" src="scripts/requeststorageaccess.js"></script>
|
5 |
+
</head>
|
6 |
+
<body>
|
7 |
+
<h2>Hi there. This is my brand. Learn about it, then click the button.</h2>
|
8 |
+
<button id="theButton">Click to return</button>
|
9 |
+
</body>
|
www2/scripts/index.js
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Helper function to get a cookie.
|
2 |
+
// From https://stackoverflow.com/questions/10730362/get-cookie-by-name
|
3 |
+
function getCookie(name) {
|
4 |
+
const value = `; ${document.cookie}`;
|
5 |
+
const parts = value.split(`; ${name}=`);
|
6 |
+
if (parts.length === 2) return parts.pop().split(';').shift();
|
7 |
+
}
|
8 |
+
|
9 |
+
document.addEventListener('DOMContentLoaded', event => {
|
10 |
+
|
11 |
+
// Always try to get the cookie.
|
12 |
+
const cookieValue = getCookie('embeddedCookie');
|
13 |
+
if (cookieValue) {
|
14 |
+
document.getElementById('cookieValue').innerText = cookieValue;
|
15 |
+
}
|
16 |
+
});
|
17 |
+
|
18 |
+
|
19 |
+
// Check for iOS / Safari.
|
20 |
+
if (!!document.hasStorageAccess) {
|
21 |
+
document.hasStorageAccess().then(result => {
|
22 |
+
|
23 |
+
// If we don't have access we must request it, but the request
|
24 |
+
// must come from a UI event.
|
25 |
+
if (!result) {
|
26 |
+
|
27 |
+
// Show the button and tie to the click.
|
28 |
+
const requestStorageAccessButton =
|
29 |
+
document.getElementById('requestStorageAccessButton');
|
30 |
+
requestStorageAccessButton.style.display = "block";
|
31 |
+
requestStorageAccessButton.addEventListener("click", event => {
|
32 |
+
|
33 |
+
// On UI event, consume the event by requesting access.
|
34 |
+
document.requestStorageAccess().then(result => {
|
35 |
+
|
36 |
+
// Finally, we are allowed! Reload to get the cookie.
|
37 |
+
window.location.reload();
|
38 |
+
}).catch(err => {
|
39 |
+
|
40 |
+
// If we get here, it means either our page
|
41 |
+
// was never loaded as a first party page,
|
42 |
+
// or the user clicked 'Don't Allow'.
|
43 |
+
// Either way open that now so the user can request
|
44 |
+
// from there (or learn more about us).
|
45 |
+
window.top.location = window.location.href +
|
46 |
+
"requeststorageaccess.html";
|
47 |
+
});
|
48 |
+
});
|
49 |
+
}
|
50 |
+
}).catch(err => console.error(err));
|
51 |
+
}
|
www2/scripts/requeststorageaccess.js
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
document.addEventListener('DOMContentLoaded', event => {
|
2 |
+
document.getElementById('theButton').addEventListener("click", event => {
|
3 |
+
|
4 |
+
// Just go back to the outside iframe we came from.
|
5 |
+
window.history.back();
|
6 |
+
});
|
7 |
+
});
|