Skip to content

Commit 4e16edd

Browse files
committed
feat: history
1 parent f533639 commit 4e16edd

File tree

8 files changed

+95
-1
lines changed

8 files changed

+95
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ send your file through onedrive
2525
1. Under `manage` select `Certificates & secrets`, click `New client secret`. Copy and keep that secret for later use.
2626
1. Under `manage` select `API permissions`, click `Add a permission` and select `Microsoft Graph` then select `delegated permissions`.
2727
1. Search and select the following permissions: `Files.ReadWrite.All`. Once selected click `Add permissions` at the bottom.
28-
1. Download [this script](https://github.com/yuudi/onesender/raw/master/init.ps1) on your Windows computer, click `run in powershell` in the right-click menu, enter your `client id` and `client secret`, and follow the instruction to get `refresh_token`. (if the script is forbidden, execute in powershell as administrator `Start-Process -Wait -Verb RunAs powershell.exe -Args "-executionpolicy bypass -command Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force`)
28+
1. Download [this script](./auth.ps1) on your Windows computer, click `run in powershell` in the right-click menu, enter your `client id` and `client secret`, and follow the instruction to get `refresh_token`. (if the script is forbidden, execute in powershell as administrator `Start-Process -Wait -Verb RunAs powershell.exe -Args "-executionpolicy bypass -command Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force`)
2929
1. When finished, `token.txt` is saved on your desktop.

assets/history.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
h1 {
2+
text-align: center;
3+
}
4+
5+
#share-history {
6+
text-align: center;
7+
margin: 100px auto;
8+
}

assets/history.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
function get_share_history() {
2+
let history_json = localStorage.sender_history;
3+
if (history_json === undefined) {
4+
return [];
5+
}
6+
return JSON.parse(history_json);
7+
}
8+
(function () {
9+
let share_display = document.getElementById("share-history");
10+
let history = get_share_history();
11+
if (history.length === 0) {
12+
share_display.innerText = "no history found";
13+
return;
14+
}
15+
for (let share of history) {
16+
let info = document.createElement("div");
17+
let read = document.createElement("a");
18+
// let write = document.createElement("a");
19+
info.innerText = share.name;
20+
read.innerText = "view";
21+
read.href = "/s/" + share.read_id;
22+
read.target = "_blank";
23+
// write.innerText = "modify";
24+
// write.href = "#";
25+
// write.addEventListener("click", function () {
26+
// return;
27+
// });
28+
info.append(document.createTextNode(" "));
29+
info.append(read);
30+
// info.append(document.createTextNode(" "));
31+
// info.append(write);
32+
info.classList.add("share-item");
33+
share_display.append(info);
34+
}
35+
})();

assets/homepage.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ h1 {
2626
margin: 100px;
2727
}
2828

29+
#history-link {
30+
text-align: center;
31+
font-size: 12px;
32+
}
33+
2934
#sharing {
3035
width: min-content;
3136
min-width: 240px;
@@ -36,3 +41,7 @@ h1 {
3641
#file-table {
3742
width: max-content;
3843
}
44+
45+
#main-display {
46+
text-align: center;
47+
}

assets/homepage.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
function share_history_append(name, read_id, write_id) {
2+
let history_json = localStorage.sender_history;
3+
if (history_json === undefined) {
4+
history_json = "[]";
5+
}
6+
let history = JSON.parse(history_json);
7+
history.push({
8+
name: name,
9+
read_id: read_id,
10+
write_id: write_id,
11+
});
12+
localStorage.sender_history = JSON.stringify(history);
13+
}
14+
115
(function () {
216
const size_unit = 327680;
317
const max_size = 192;
@@ -105,6 +119,11 @@
105119
}
106120
main_display.innerText =
107121
"your share has been created. you can send this link to your friends";
122+
share_history_append(
123+
files[0].file.name + (files.length > 1 ? " and other files" : ""),
124+
read_id,
125+
write_id
126+
);
108127
let share_url = location.origin + "/s/" + read_id;
109128
let link = document.createElement("a");
110129
link.innerText = share_url;

history.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width,initial-scale=1" />
6+
<title>Share file</title>
7+
<script src="/assets/history.js" defer></script>
8+
<link rel="stylesheet" href="/assets/history.css" />
9+
<link rel="icon" href="/assets/favicon.ico" />
10+
</head>
11+
<body>
12+
<h1>History</h1>
13+
<div id="share-history"></div>
14+
</body>
15+
</html>

homepage.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ <h1>Share your files</h1>
1717
Create Share
1818
</button>
1919
</div>
20+
<div id="history-link"><a href="/history">history</a></div>
2021
<div id="sharing" hidden>
2122
<table id="file-table">
2223
<tbody id="file-list"></tbody>

onesend.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ var publicIndex []byte
3131
//go:embed receive.html
3232
var publicReceive []byte
3333

34+
//go:embed history.html
35+
var publicHistory []byte
36+
3437
//go:embed assets
3538
var publicAssets embed.FS
3639

@@ -223,6 +226,10 @@ func entry() error {
223226
c.Header("Cache-Control", "public, max-age=604800")
224227
c.Data(200, "text/html", publicIndex)
225228
})
229+
r.GET("/history", func(c *gin.Context) {
230+
c.Header("Cache-Control", "public, max-age=604800")
231+
c.Data(200, "text/html", publicHistory)
232+
})
226233
r.GET("/s/:read_id", func(c *gin.Context) {
227234
//readID := c.Param("read_id")
228235
//if pusher := c.Writer.Pusher(); pusher != nil {

0 commit comments

Comments
 (0)