Skip to content

Commit

Permalink
Add initial project structure with Docker support and web UI for Baid…
Browse files Browse the repository at this point in the history
…u NetDisk transfer
  • Loading branch information
LogicDX342 committed Nov 7, 2024
1 parent 12f6ed3 commit 0478d98
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
Binary file added BaiduPCS-Go
Binary file not shown.
8 changes: 8 additions & 0 deletions Dockerfile
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"]
11 changes: 10 additions & 1 deletion README.md
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.
51 changes: 51 additions & 0 deletions app.py
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)
12 changes: 12 additions & 0 deletions docker-compose.yml
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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Flask==3.0.3
54 changes: 54 additions & 0 deletions templates/index.html
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>

0 comments on commit 0478d98

Please sign in to comment.