-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial project structure with Docker support and web UI for Baid…
…u NetDisk transfer
- Loading branch information
1 parent
12f6ed3
commit 0478d98
Showing
8 changed files
with
137 additions
and
1 deletion.
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 @@ | ||
__pycache__/ |
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,8 @@ | ||
FROM python:3.12.7-alpine3.20 | ||
WORKDIR /app | ||
COPY . /app | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
RUN chmod +x /app/BaiduPCS-Go | ||
ENV BAIDUPCS_GO_CONFIG_DIR=/config | ||
EXPOSE 5000 | ||
ENTRYPOINT ["python", "app.py"] |
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 |
---|---|---|
@@ -1 +1,10 @@ | ||
# BaiduNetDiskTransfer-WebUI | ||
# BaiduNetDiskTransfer-WebUI | ||
|
||
A simple web UI for Baidu NetDisk Share Link Transfer. | ||
|
||
## Environment Variables | ||
|
||
You can configure the following environment variables in the `docker-compose.yml` file: | ||
|
||
- `COOKIES`: The cookies for BaiduPCS-Go login. | ||
- `TRANSFER_DIR`: The directory where files will be transferred. |
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,51 @@ | ||
from flask import Flask, render_template, request, Response | ||
import subprocess | ||
import os | ||
|
||
def init(): | ||
cookies = os.getenv('COOKIES', '') | ||
bduss = '' | ||
stoken = '' | ||
for cookie in cookies.split(';'): | ||
if 'BDUSS' in cookie: | ||
bduss = cookie.split('=')[1] | ||
if 'STOKEN' in cookie: | ||
stoken = cookie.split('=')[1] | ||
if not bduss or not stoken: | ||
raise Exception('BDUSS or STOKEN not found in cookies') | ||
download_dir = os.getenv('TRANSFER_DIR', '/PCS-Transfer') | ||
|
||
commands = [ | ||
['./BaiduPCS-Go', 'login', '--bduss', bduss, '--stoken', stoken], | ||
['./BaiduPCS-Go', 'mkdir', download_dir], | ||
['./BaiduPCS-Go', 'cd', download_dir] | ||
] | ||
|
||
for command in commands: | ||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | ||
for line in process.stdout: | ||
print(line) | ||
for line in process.stderr: | ||
print(line) | ||
|
||
app = Flask(__name__) | ||
with app.app_context(): | ||
init() | ||
|
||
@app.route('/', methods=['GET', 'POST']) | ||
def index(): | ||
return render_template('index.html') | ||
|
||
@app.route('/transfer', methods=['GET']) | ||
def transfer(): | ||
share_link = request.args.get('share_link') | ||
def generate(): | ||
process = subprocess.Popen(['./BaiduPCS-Go', 'transfer', share_link, '--collect'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | ||
for line in process.stdout: | ||
yield f"data:{line}\n\n" | ||
for line in process.stderr: | ||
yield f"data:{line}\n\n" | ||
return Response(generate(), mimetype='text/event-stream') | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=True) |
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,12 @@ | ||
version: '3.8' | ||
|
||
services: | ||
baidunetdisk-transfer: | ||
image: "logicdx342/baidunetdisktransfer-webui:latest" | ||
ports: | ||
- "5000:5000" | ||
volumes: | ||
- ./config:/config | ||
environment: | ||
- COOKIES="" | ||
- TRANSFER_DIR=/PCS-Transfer |
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 @@ | ||
Flask==3.0.3 |
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,54 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"> | ||
<title>BaiduNetDisk Transfer</title> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<h1 class="mt-5">BaiduNetDisk Transfer</h1> | ||
<form id="transfer-form"> | ||
<div class="form-group"> | ||
<label for="share_link">Share Link</label> | ||
<input type="text" class="form-control" id="share_link" name="share_link" | ||
placeholder="Enter BaiduNetDisk share link"> | ||
</div> | ||
<button type="submit" class="btn btn-primary">Transfer</button> | ||
<div class="mt-3"> | ||
<pre> | ||
Sample share links: | ||
pan.baidu.com/s/1VYzSl7465sdrQXe8GT5RdQ 704e | ||
https://pan.baidu.com/s/1VYzSl7465sdrQXe8GT5RdQ 704e | ||
https://pan.baidu.com/s/1VYzSl7465sdrQXe8GT5RdQ?pwd=704e | ||
</pre> | ||
</div> | ||
</form> | ||
<div class="mt-3"> | ||
<label for="output">Output:</label> | ||
<textarea id="output" class="form-control" rows="10" readonly></textarea> | ||
</div> | ||
</div> | ||
<script> | ||
document.getElementById('transfer-form').addEventListener('submit', function (event) { | ||
event.preventDefault(); | ||
const shareLink = document.getElementById('share_link').value; | ||
const output = document.getElementById('output'); | ||
output.value = ''; | ||
|
||
const eventSource = new EventSource('/transfer?' + new URLSearchParams({ share_link: shareLink })); | ||
eventSource.onmessage = function (event) { | ||
output.value += event.data + '\n'; | ||
output.scrollTop = output.scrollHeight; | ||
}; | ||
eventSource.onerror = function () { | ||
eventSource.close(); | ||
}; | ||
}); | ||
</script> | ||
</body> | ||
|
||
</html> |