-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1e62c16
Showing
13 changed files
with
1,229 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: ci | ||
|
||
on: | ||
push: {} | ||
pull_request: | ||
types: | ||
- opened | ||
- synchronize | ||
workflow_dispatch: {} | ||
|
||
jobs: | ||
build: | ||
name: Build Go Binaries | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout the repo | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
submodules: true | ||
|
||
- name: Setup go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.16 | ||
|
||
- name: Cache go modules | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('./go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Minify HTML files | ||
run: | | ||
npm install html-minifier -g | ||
html-minifier --collapse-whitespace --minify-css true --minify-js true index.html>index.min.html | ||
html-minifier --collapse-whitespace --minify-css true --minify-js true receive.html>receive.min.html | ||
mv index.min.html index.html | ||
mv receive.min.html receive.html | ||
- name: Build | ||
run: | | ||
export GOOS=linux | ||
export GOARCH=amd64 | ||
go build -trimpath -ldflags="-s -w" -o "dist/onesend" . | ||
export GOOS=windows | ||
export GOARCH=amd64 | ||
go build -trimpath -ldflags="-s -w" -o "dist/onesend.exe" . | ||
cd dist | ||
tar zcf onesend-test-${GITHUB_SHA:0:7}-linux-x86_64.tar.gz onesend | ||
zip onesend-test-${GITHUB_SHA:0:7}-windows-x86_64.zip onesend.exe | ||
- name: Upload artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: executable | ||
path: | | ||
dist/*.tar.gz | ||
dist/*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# MacOS | ||
.DS_Store | ||
|
||
# Editors | ||
.vscode | ||
.idea/* | ||
# track codeStyles configuration files | ||
!.idea/codeStyles | ||
|
||
# Binaries | ||
dist |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2021 yuudi | ||
|
||
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: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# onesender | ||
|
||
send your file through onedrive | ||
|
||
## usage | ||
|
||
1. download from release and unzip | ||
2. fill in *config.toml* | ||
3. fill your refresh token into *token.txt* (you can refer to [auth](#auth)) | ||
4. run program | ||
|
||
## configuration | ||
|
||
**ClientID**: client id | ||
**ClientSecret**: client secret | ||
**AccountArea**: the area of your onedrive account, can be ("global" | "gov" | "de" | "cn") | ||
**SavePath**: where to save files in your onedrive | ||
**Listen**: how the program bind address | ||
|
||
## auth | ||
|
||
1. Open <https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade> and then click `New registration`. | ||
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. | ||
1. Under `manage` select `Certificates & secrets`, click `New client secret`. Copy and keep that secret for later use. | ||
1. Under `manage` select `API permissions`, click `Add a permission` and select `Microsoft Graph` then select `delegated permissions`. | ||
1. Search and select the following permissions: `Files.ReadWrite.All`. Once selected click `Add permissions` at the bottom. | ||
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`) | ||
1. When finished, `token.txt` is saved on your desktop. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
$ErrorActionPreference = "Stop" | ||
|
||
Write-Output "choose the account area | ||
1> global | ||
2> us government | ||
3> Germany | ||
4> China (operated by 21Vianet) | ||
" | ||
$account_area = Read-Host 'account type' | ||
switch ($account_area) { | ||
1 { $auth_host = "login.microsoftonline.com" } | ||
2 { $auth_host = "login.microsoftonline.us" } | ||
3 { $auth_host = "login.microsoftonline.de" } | ||
4 { $auth_host = "login.chinacloudapi.cn" } | ||
Default { exit } | ||
} | ||
|
||
$client_id = Read-Host 'client_id' | ||
$client_secret = Read-Host 'client_secret' | ||
|
||
$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" | ||
$auth_code = "" | ||
|
||
$http = [System.Net.HttpListener]::new() | ||
$http.Prefixes.Add("http://localhost:53682/") | ||
$http.Start() | ||
|
||
Start-Process $auth_url | ||
|
||
while ($http.IsListening) { | ||
Start-Sleep -Seconds 0.1 | ||
$context = $http.GetContext() | ||
$code = $context.Request.QueryString.Get("code") | ||
if ($code) { | ||
$auth_code = $code | ||
[string]$html = "<p>success, now you can close this window</p>" | ||
$buffer = [System.Text.Encoding]::UTF8.GetBytes($html) | ||
$context.Response.ContentLength64 = $buffer.Length | ||
$context.Response.OutputStream.Write($buffer, 0, $buffer.Length) | ||
$context.Response.OutputStream.Close() | ||
break | ||
} | ||
else { | ||
[string]$html = "<p>error, please continue <a href='${auth_url}'>here</a></p>" | ||
$buffer = [System.Text.Encoding]::UTF8.GetBytes($html) | ||
$context.Response.ContentLength64 = $buffer.Length | ||
$context.Response.OutputStream.Write($buffer, 0, $buffer.Length) | ||
$context.Response.OutputStream.Close() | ||
} | ||
} | ||
|
||
Write-Output "code received, start fetching token" | ||
|
||
$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" | ||
|
||
$res = Invoke-RestMethod "https://login.microsoftonline.com/common/oauth2/v2.0/token" -Method "POST" -Body $reqdata | ||
$refresh_token = $res.refresh_token | ||
|
||
$desktop = [Environment]::GetFolderPath("Desktop") | ||
New-Item -Path $desktop\token.txt -ItemType File -Value $refresh_token | ||
|
||
Write-Output @" | ||
========== | ||
${refresh_token} | ||
========== | ||
this is your refresh_token, keep it safe | ||
it has been saved on your desktop | ||
"@ | ||
|
||
cmd /C PAUSE |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module github.com/yuudi/onesender | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/BurntSushi/toml v0.4.0 // indirect | ||
github.com/gin-gonic/gin v1.7.3 // indirect | ||
github.com/robfig/cron/v3 v3.0.1 // indirect | ||
golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 // indirect | ||
) |
Oops, something went wrong.