Skip to content

Commit 7acc5eb

Browse files
committed
Add logo for going to home. Fix origin check
1 parent 3cd0529 commit 7acc5eb

File tree

5 files changed

+164
-74
lines changed

5 files changed

+164
-74
lines changed

ports/espressif/fatfs_port.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,26 @@
2626

2727
#include "py/runtime.h"
2828
#include "lib/oofatfs/ff.h"
29+
#include "shared/timeutils/timeutils.h"
30+
#include "shared-bindings/rtc/RTC.h"
31+
#include "shared-bindings/time/__init__.h"
32+
#include "supervisor/fatfs_port.h"
2933

34+
DWORD _time_override = 0;
3035
DWORD get_fattime(void) {
31-
// TODO: Implement this function. For now, fake it.
32-
return ((2016 - 1980) << 25) | ((12) << 21) | ((4) << 16) | ((00) << 11) | ((18) << 5) | (23 / 2);
36+
if (_time_override > 0) {
37+
return _time_override;
38+
}
39+
#if CIRCUITPY_RTC
40+
timeutils_struct_time_t tm;
41+
common_hal_rtc_get_time(&tm);
42+
return ((tm.tm_year - 1980) << 25) | (tm.tm_mon << 21) | (tm.tm_mday << 16) |
43+
(tm.tm_hour << 11) | (tm.tm_min << 5) | (tm.tm_sec >> 1);
44+
#else
45+
return ((2016 - 1980) << 25) | ((9) << 21) | ((1) << 16) | ((16) << 11) | ((43) << 5) | (35 / 2);
46+
#endif
47+
}
48+
49+
void override_fattime(DWORD time) {
50+
_time_override = time;
3351
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<!DOCTYPE html><html><head><title></title><meta charset="UTF-8"></head>
22
<script src="/directory.js" defer=true></script>
3-
<body><h1></h1><template id="row"><tr><td></td><td></td><td><a></a></td><td></td><td><button class="delete">🗑️</button></td></tr></template><table><thead><tr><th>Type</th><th>Size</th><th>Path</th><th>Modified</th><th></th></tr></thead><tbody></tbody></table><hr><input type="file" id="files" multiple><button type="submit" id="upload">Upload</button><hr>+🗀&nbsp;<input type="text" id="name"><button type="submit" id="mkdir">Create Directory</button>
3+
<body><h1><a href="/"><img src="/favicon.ico"/></a>&nbsp;<span id="path"></span></h1><template id="row"><tr><td></td><td></td><td><a></a></td><td></td><td><button class="delete">🗑️</button></td></tr></template><table><thead><tr><th>Type</th><th>Size</th><th>Path</th><th>Modified</th><th></th></tr></thead><tbody></tbody></table><hr><input type="file" id="files" multiple><button type="submit" id="upload">Upload</button><hr>+🗀&nbsp;<input type="text" id="name"><button type="submit" id="mkdir">Create Directory</button>
44
</body></html>

supervisor/shared/web_workflow/static/directory.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ let files = document.getElementById("files");
33

44
var url_base = window.location;
55
var current_path;
6+
var editable = undefined;
67

78
async function refresh_list() {
89
current_path = window.location.hash.substr(1);
910
if (current_path == "") {
1011
current_path = "/";
1112
}
13+
// Do the fetch first because the browser will prompt for credentials.
1214
const response = await fetch(new URL("/fs" + current_path, url_base),
1315
{
1416
headers: {
@@ -19,8 +21,24 @@ async function refresh_list() {
1921
);
2022
const data = await response.json();
2123
var new_children = [];
24+
var title = document.querySelector("title");
25+
title.textContent = current_path;
26+
var path = document.querySelector("#path");
27+
path.textContent = current_path;
2228
var template = document.querySelector('#row');
2329

30+
if (editable === undefined) {
31+
const status = await fetch(new URL("/fs/", url_base),
32+
{
33+
method: "OPTIONS",
34+
credentials: "include"
35+
}
36+
);
37+
editable = status.headers.get("Access-Control-Allow-Methods").includes("DELETE");
38+
new_directory_name.disabled = !editable;
39+
files.disabled = !editable;
40+
}
41+
2442
if (window.location.path != "/fs/") {
2543
var clone = template.content.cloneNode(true);
2644
var td = clone.querySelectorAll("td");
@@ -66,8 +84,10 @@ async function refresh_list() {
6684
td[3].textContent = (new Date(f.modified_ns / 1000000)).toLocaleString();
6785
var delete_button = clone.querySelector("button.delete");
6886
delete_button.value = api_url;
87+
delete_button.disabled = !editable;
6988
delete_button.onclick = del;
7089

90+
7191
new_children.push(clone);
7292
}
7393
var tbody = document.querySelector("tbody");

supervisor/shared/web_workflow/static/welcome.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</head>
77
<script src="/welcome.js" defer=true></script>
88
<body>
9-
<h1>Welcome!</h1>
9+
<h1><a href="/"><img src="/favicon.ico"/></a>&nbsp;Welcome!</h1>
1010
Welcome to CircuitPython's Web API. Through your browser you can <a href="/fs/">work with files</a>. Make sure you've set <code>CIRCUITPY_WEB_API_PASSWORD</code> in <code>/.env</code> and provide it when the browser prompts for it. Leave the username blank.
1111
<h2>Device Info</h2>
1212
Board: <a id="board"></a><br>

0 commit comments

Comments
 (0)