Skip to content

Commit 1e62c16

Browse files
committed
init
0 parents  commit 1e62c16

File tree

13 files changed

+1229
-0
lines changed

13 files changed

+1229
-0
lines changed

.github/workflows/CI.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: ci
2+
3+
on:
4+
push: {}
5+
pull_request:
6+
types:
7+
- opened
8+
- synchronize
9+
workflow_dispatch: {}
10+
11+
jobs:
12+
build:
13+
name: Build Go Binaries
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout the repo
18+
uses: actions/checkout@v2
19+
with:
20+
fetch-depth: 0
21+
submodules: true
22+
23+
- name: Setup go
24+
uses: actions/setup-go@v2
25+
with:
26+
go-version: 1.16
27+
28+
- name: Cache go modules
29+
uses: actions/cache@v2
30+
with:
31+
path: ~/go/pkg/mod
32+
key: ${{ runner.os }}-go-${{ hashFiles('./go.sum') }}
33+
restore-keys: |
34+
${{ runner.os }}-go-
35+
36+
- name: Minify HTML files
37+
run: |
38+
npm install html-minifier -g
39+
html-minifier --collapse-whitespace --minify-css true --minify-js true index.html>index.min.html
40+
html-minifier --collapse-whitespace --minify-css true --minify-js true receive.html>receive.min.html
41+
mv index.min.html index.html
42+
mv receive.min.html receive.html
43+
44+
- name: Build
45+
run: |
46+
export GOOS=linux
47+
export GOARCH=amd64
48+
go build -trimpath -ldflags="-s -w" -o "dist/onesend" .
49+
50+
export GOOS=windows
51+
export GOARCH=amd64
52+
go build -trimpath -ldflags="-s -w" -o "dist/onesend.exe" .
53+
54+
cd dist
55+
tar zcf onesend-test-${GITHUB_SHA:0:7}-linux-x86_64.tar.gz onesend
56+
zip onesend-test-${GITHUB_SHA:0:7}-windows-x86_64.zip onesend.exe
57+
58+
- name: Upload artifact
59+
uses: actions/upload-artifact@v2
60+
with:
61+
name: executable
62+
path: |
63+
dist/*.tar.gz
64+
dist/*.zip

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories (remove the comment below to include it)
15+
# vendor/
16+
17+
# MacOS
18+
.DS_Store
19+
20+
# Editors
21+
.vscode
22+
.idea/*
23+
# track codeStyles configuration files
24+
!.idea/codeStyles
25+
26+
# Binaries
27+
dist

.idea/codeStyles/Project.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LECENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2021 yuudi
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# onesender
2+
3+
send your file through onedrive
4+
5+
## usage
6+
7+
1. download from release and unzip
8+
2. fill in *config.toml*
9+
3. fill your refresh token into *token.txt* (you can refer to [auth](#auth))
10+
4. run program
11+
12+
## configuration
13+
14+
**ClientID**: client id
15+
**ClientSecret**: client secret
16+
**AccountArea**: the area of your onedrive account, can be ("global" | "gov" | "de" | "cn")
17+
**SavePath**: where to save files in your onedrive
18+
**Listen**: how the program bind address
19+
20+
## auth
21+
22+
1. Open <https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade> and then click `New registration`.
23+
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.
24+
1. Under `manage` select `Certificates & secrets`, click `New client secret`. Copy and keep that secret for later use.
25+
1. Under `manage` select `API permissions`, click `Add a permission` and select `Microsoft Graph` then select `delegated permissions`.
26+
1. Search and select the following permissions: `Files.ReadWrite.All`. Once selected click `Add permissions` at the bottom.
27+
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. When finished, `token.txt` is saved on your desktop.

auth.ps1

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
$ErrorActionPreference = "Stop"
2+
3+
Write-Output "choose the account area
4+
1> global
5+
2> us government
6+
3> Germany
7+
4> China (operated by 21Vianet)
8+
9+
"
10+
$account_area = Read-Host 'account type'
11+
switch ($account_area) {
12+
1 { $auth_host = "login.microsoftonline.com" }
13+
2 { $auth_host = "login.microsoftonline.us" }
14+
3 { $auth_host = "login.microsoftonline.de" }
15+
4 { $auth_host = "login.chinacloudapi.cn" }
16+
Default { exit }
17+
}
18+
19+
$client_id = Read-Host 'client_id'
20+
$client_secret = Read-Host 'client_secret'
21+
22+
$auth_url = "https://${auth_host}/common/oauth2/v2.0/authorize?client_id=${client_id}&response_type=code&redirect_uri=http://localhost:53682/&response_mode=query&scope=offline_access%20Files.ReadWrite.All"
23+
$auth_code = ""
24+
25+
$http = [System.Net.HttpListener]::new()
26+
$http.Prefixes.Add("http://localhost:53682/")
27+
$http.Start()
28+
29+
Start-Process $auth_url
30+
31+
while ($http.IsListening) {
32+
Start-Sleep -Seconds 0.1
33+
$context = $http.GetContext()
34+
$code = $context.Request.QueryString.Get("code")
35+
if ($code) {
36+
$auth_code = $code
37+
[string]$html = "<p>success, now you can close this window</p>"
38+
$buffer = [System.Text.Encoding]::UTF8.GetBytes($html)
39+
$context.Response.ContentLength64 = $buffer.Length
40+
$context.Response.OutputStream.Write($buffer, 0, $buffer.Length)
41+
$context.Response.OutputStream.Close()
42+
break
43+
}
44+
else {
45+
[string]$html = "<p>error, please continue <a href='${auth_url}'>here</a></p>"
46+
$buffer = [System.Text.Encoding]::UTF8.GetBytes($html)
47+
$context.Response.ContentLength64 = $buffer.Length
48+
$context.Response.OutputStream.Write($buffer, 0, $buffer.Length)
49+
$context.Response.OutputStream.Close()
50+
}
51+
}
52+
53+
Write-Output "code received, start fetching token"
54+
55+
$reqdata = "client_id=${client_id}&client_secret=${client_secret}&grant_type=authorization_code&code=${auth_code}&redirect_uri=http://localhost:53682/&scope=offline_access%20Files.Read.All%20Files.ReadWrite.All%20Sites.Read.All%20Sites.ReadWrite.All%20User.Read.All%20User.ReadWrite.All%20Directory.Read.All%20Directory.ReadWrite.All%20Mail.Read%20Mail.ReadWrite%20MailboxSettings.Read%20MailboxSettings.ReadWrite"
56+
57+
$res = Invoke-RestMethod "https://login.microsoftonline.com/common/oauth2/v2.0/token" -Method "POST" -Body $reqdata
58+
$refresh_token = $res.refresh_token
59+
60+
$desktop = [Environment]::GetFolderPath("Desktop")
61+
New-Item -Path $desktop\token.txt -ItemType File -Value $refresh_token
62+
63+
Write-Output @"
64+
==========
65+
${refresh_token}
66+
==========
67+
this is your refresh_token, keep it safe
68+
it has been saved on your desktop
69+
"@
70+
71+
cmd /C PAUSE

favicon.ico

70 Bytes
Binary file not shown.

go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/yuudi/onesender
2+
3+
go 1.16
4+
5+
require (
6+
github.com/BurntSushi/toml v0.4.0 // indirect
7+
github.com/gin-gonic/gin v1.7.3 // indirect
8+
github.com/robfig/cron/v3 v3.0.1 // indirect
9+
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 // indirect
10+
)

0 commit comments

Comments
 (0)