Skip to content

Commit 99bf729

Browse files
committed
simplify deploying process
1 parent 181666e commit 99bf729

File tree

8 files changed

+231
-86
lines changed

8 files changed

+231
-86
lines changed

.github/workflows/CI.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
name: ci
22

33
on:
4-
push: {}
4+
push:
5+
branches:
6+
- master
57
pull_request:
68
types:
79
- opened
@@ -41,7 +43,7 @@ jobs:
4143
export GOOS=linux
4244
export GOARCH=amd64
4345
go build -trimpath -ldflags="-s -w" -o "dist/onesend-amd64" .
44-
46+
4547
export GOOS=linux
4648
export GOARCH=arm64
4749
go build -trimpath -ldflags="-s -w" -o "dist/onesend-arm64" .

README.md

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,18 @@ send your file through onedrive
2222

2323
## Limitations
2424

25-
- **MUST** hosted on https site
26-
- Cannot work in Firefox InPrivate window
27-
- Leaving downloading page will interrupt downloading
25+
- **MUST** hosted on https site
26+
- Cannot work in Firefox InPrivate window
27+
- Leaving downloading page will interrupt downloading
2828

2929
## Deploy
3030

3131
1. download from release and unzip
32-
2. fill in _config.toml_
33-
3. fill your refresh token into _token.txt_ (you can refer to [Authorization](#Authorization))
34-
4. run program
32+
1. run program
3533

3634
## Configuration
3735

38-
**ClientID**: client id
39-
**ClientSecret**: client secret
40-
**AccountArea**: the area of your onedrive account, can be ("global" | "gov" | "de" | "cn")
41-
**Drive**: the drive path to use. default: "/me/drive"
4236
**SavePath**: where to save files in your onedrive
4337
**Listen**: how the program bind address
4438

45-
## Authorization
46-
47-
1. Open <https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade> and then click `New registration`.
48-
1. Enter a name for your app, choose account type `Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)`, select `Web` in `Redirect URI`, then type `http://localhost:53682/` and click Register. Copy and keep the `Application (client) ID` under the app name for later use.
49-
1. Under `manage` select `Certificates & secrets`, click `New client secret`. Copy and keep that secret value for later use (secret value, not secret ID).
50-
1. Under `manage` select `API permissions`, click `Add a permission` and select `Microsoft Graph` then select `delegated permissions`.
51-
1. Search and select the following permissions: `Files.ReadWrite.All`. Once selected click `Add permissions` at the bottom.
52-
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`)
53-
1. When finished, `token.txt` is saved on your desktop.
39+
if you want to use your private client_id and client_secret to setup this app, you can check [This Instruction](./docs/Private-App.md)

auth.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Authorize</title>
8+
<link rel="icon" href="data:;" />
9+
</head>
10+
11+
<body>
12+
<h1>Authorize Onedrive Access</h1>
13+
<p>Click the button below to authorize access to your Onedrive account.</p>
14+
<button id="auth">Authorize</button>
15+
<script>
16+
(function () {
17+
if (!isSecureContext) {
18+
alert('This page must be accessed via HTTPS.');
19+
document.body.innerText = 'This app use service worker to emulate download, and service worker only works on HTTPS. Please setup an HTTPS reverse proxy to host this app.'
20+
return
21+
}
22+
const button = document.getElementById('auth');
23+
button.addEventListener('click', () => {
24+
let redirect = (new URL('./oauth', document.baseURI)).href;
25+
window.location = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=5114220a-e543-4bc0-b1aa-c84fced70454&response_type=code&redirect_uri=https://yuudi.github.io/onesend/oauth/index.html&response_mode=query&scope=offline_access%20Files.ReadWrite.All&state=" + encodeURIComponent(redirect);
26+
});
27+
})()
28+
</script>
29+
</body>
30+
31+
</html>

config.sample.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[Onedrive]
22
ClientID = ""
33
ClientSecret = ""
4+
# Leave Empty for default
45

56
# Global or Personal
67
AccountArea = "global"

docs/Private-App.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Private App
2+
3+
If you want to use your private client_id and client_secret to setup this app, you can follow the steps below.
4+
5+
## Authorization
6+
7+
1. Open <https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade> and then click `New registration`.
8+
1. Enter a name for your app, choose account type `Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)`, select `Web` in `Redirect URI`, then type `http://localhost:53682/` and click Register. Copy and keep the `Application (client) ID` under the app name for later use.
9+
1. Under `manage` select `Certificates & secrets`, click `New client secret`. Copy and keep that secret value for later use (secret value, not secret ID).
10+
1. Under `manage` select `API permissions`, click `Add a permission` and select `Microsoft Graph` then select `delegated permissions`.
11+
1. Search and select the following permissions: `Files.ReadWrite.All`. Once selected click `Add permissions` at the bottom.
12+
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`)
13+
1. When finished, `token.txt` is saved on your desktop.
14+
15+
## Configuration
16+
17+
open `config.toml` and fill in the following fields:
18+
19+
**ClientID**: client id
20+
**ClientSecret**: client secret
21+
**AccountArea**: the area of your onedrive account, can be ("global" | "gov" | "de" | "cn")
22+
**Drive**: the drive path to use. default: "/me/drive"
23+
24+
open `token.txt` and copy the refresh token to the file.
File renamed without changes.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/yuudi/onesender
1+
module github.com/yuudi/onesend
22

33
go 1.20
44

0 commit comments

Comments
 (0)