Compare commits
11 Commits
a2f1b6d4fd
...
master
Author | SHA1 | Date | |
---|---|---|---|
27490823d6 | |||
88c62f3b97 | |||
8ff9869399 | |||
b25c43458a | |||
4d00138b32 | |||
52b2e0e56b | |||
164d120220 | |||
67c4bfb9ac | |||
15885c5676 | |||
a2caaddef4 | |||
8f884cc352 |
63
.drone.yml
Normal file
63
.drone.yml
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
kind: pipeline # 定义一个管道
|
||||||
|
type: docker # 当前管道的类型
|
||||||
|
name: build # 当前管道的名称
|
||||||
|
|
||||||
|
steps: # 定义管道的执行步骤
|
||||||
|
# - name: build-project # 步骤名称
|
||||||
|
# image: node:18-bullseye # 当前步骤使用的镜像
|
||||||
|
# volumes:
|
||||||
|
# - name: node_modules
|
||||||
|
# path: /drone/src/node_modules
|
||||||
|
# commands: # 当前步骤执行的命令
|
||||||
|
# - pwd
|
||||||
|
# - npm config set registry https://registry.npm.taobao.org
|
||||||
|
# - npm i
|
||||||
|
|
||||||
|
- name: build-image
|
||||||
|
image: plugins/docker
|
||||||
|
depends_on: [clone]
|
||||||
|
settings:
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
password:
|
||||||
|
from_secret: docker_passwd
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
mirror: https://fpswa5tm.mirror.aliyuncs.com
|
||||||
|
registry: https://git.liliyamol.cn
|
||||||
|
repo: git.liliyamol.cn/mol/middle-server
|
||||||
|
auto_tag: true
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline # 定义一个管道
|
||||||
|
type: docker # 当前管道的类型
|
||||||
|
name: deploy # 当前管道的名称
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- build
|
||||||
|
|
||||||
|
clone:
|
||||||
|
disable: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: deploy-project
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
settings:
|
||||||
|
host:
|
||||||
|
from_secret: host
|
||||||
|
username:
|
||||||
|
from_secret: server_username # 使用secrets
|
||||||
|
key:
|
||||||
|
from_secret: server_key
|
||||||
|
port: 22
|
||||||
|
command_timeout: 2m
|
||||||
|
secrets: [docker_username, docker_passwd]
|
||||||
|
script:
|
||||||
|
- echo ==-----==开始部署==-----==
|
||||||
|
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWD git.liliyamol.cn
|
||||||
|
- docker pull git.liliyamol.cn/mol/middle-server:latest
|
||||||
|
- list=$(docker ps -a | grep middle_server* | awk '{print $1}')
|
||||||
|
- test "$list" = "" && echo "none middle_server containers running" || docker stop $list && docker container rm $list
|
||||||
|
# 过滤出dockerImages的id, 删除none镜像
|
||||||
|
- docker run -d -p 15000:80 --restart=always --name=middle_server git.liliyamol.cn/mol/middle-server:latest
|
||||||
|
- docker rmi $(docker images | grep "none" | awk '{print $3}')
|
||||||
|
- echo ==-----==部署成功==-----==
|
140
.gitignore
vendored
Normal file
140
.gitignore
vendored
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
# ---> Python
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
.pybuilder/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# .python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
.pytype/
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
cython_debug/
|
||||||
|
|
9
Dockerfile
Normal file
9
Dockerfile
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
FROM python:3.6
|
||||||
|
WORKDIR /Project/Middle-server
|
||||||
|
|
||||||
|
COPY requirements.txt ./
|
||||||
|
RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
CMD ["gunicorn", "start:app", "-c", "./gunicorn.conf.py"]
|
12
Gateway.py
12
Gateway.py
@ -59,7 +59,7 @@ class GenericGateway(object):
|
|||||||
logger.info("Register route: %s", route.path)
|
logger.info("Register route: %s", route.path)
|
||||||
|
|
||||||
def proxy_request(*args, **kwargs):
|
def proxy_request(*args, **kwargs):
|
||||||
|
print('成功代理', route.name)
|
||||||
upstream_path = route.upstream_path
|
upstream_path = route.upstream_path
|
||||||
for p_name in route.upstream_params:
|
for p_name in route.upstream_params:
|
||||||
v = get_params_from_context(p_name, kwargs)
|
v = get_params_from_context(p_name, kwargs)
|
||||||
@ -79,6 +79,7 @@ class GenericGateway(object):
|
|||||||
if request.form:
|
if request.form:
|
||||||
upstream_req_info['data'] = request.form
|
upstream_req_info['data'] = request.form
|
||||||
|
|
||||||
|
# print('upstream_req_info', upstream_req_info)
|
||||||
for pipe_handler in route.inbound_pipes():
|
for pipe_handler in route.inbound_pipes():
|
||||||
upstream_req_info, args, kwargs = pipe_handler(upstream_req_info, *args, **kwargs)
|
upstream_req_info, args, kwargs = pipe_handler(upstream_req_info, *args, **kwargs)
|
||||||
|
|
||||||
@ -88,20 +89,23 @@ class GenericGateway(object):
|
|||||||
upstream_req_info['headers'] = {k: v for k, v in upstream_req_info['headers'].items()}
|
upstream_req_info['headers'] = {k: v for k, v in upstream_req_info['headers'].items()}
|
||||||
upstream_req_info['headers'].pop('Content-Type', None)
|
upstream_req_info['headers'].pop('Content-Type', None)
|
||||||
upstream_req_info['headers'].pop('content-type', None)
|
upstream_req_info['headers'].pop('content-type', None)
|
||||||
|
|
||||||
|
# print('upstream_req_info', upstream_req_info)
|
||||||
resp = requests.request(**upstream_req_info)
|
resp = requests.request(**upstream_req_info)
|
||||||
|
# print(resp.headers)
|
||||||
status = resp.status_code
|
status = resp.status_code
|
||||||
content = None
|
content = None
|
||||||
headers = resp.headers
|
headers = resp.headers
|
||||||
|
print(route.outbound_pipes())
|
||||||
for pipe_handler in route.outbound_pipes():
|
for pipe_handler in route.outbound_pipes():
|
||||||
resp, headers, status, content = pipe_handler(resp, headers, status, content, *args, **kwargs)
|
resp, headers, status, content = pipe_handler(resp, headers, status, content, *args, **kwargs)
|
||||||
|
|
||||||
content = make_response(content or resp.content)
|
content = make_response(content or resp.content)
|
||||||
for h_name, h_value in (headers or {}).items():
|
for h_name, h_value in (headers or {}).items():
|
||||||
|
# print(h_name, h_value)
|
||||||
content.headers[h_name] = h_value
|
content.headers[h_name] = h_value
|
||||||
|
# print('content', headers)
|
||||||
return content, status
|
return content, status
|
||||||
|
|
||||||
# 修改函数名称:Flask route注册使用func name必须唯一
|
# 修改函数名称:Flask route注册使用func name必须唯一
|
||||||
proxy_request.__name__ = route.name
|
proxy_request.__name__ = route.name
|
||||||
return proxy_request
|
return proxy_request
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
__pycache__/gunicorn.conf.cpython-310.pyc
Normal file
BIN
__pycache__/gunicorn.conf.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
3
gunicorn.conf.py
Normal file
3
gunicorn.conf.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
workers = 5 # 定义同时开启的处理请求的进程数量,根据网站流量适当调整
|
||||||
|
worker_class = "gevent" # 采用gevent库,支持异步处理请求,提高吞吐量
|
||||||
|
bind = "0.0.0.0:80"
|
@ -8,8 +8,9 @@ class MusicHandler(OutboundHandler):
|
|||||||
:return: (request, args, kwargs)
|
:return: (request, args, kwargs)
|
||||||
"""
|
"""
|
||||||
# raise NotImplementedError
|
# raise NotImplementedError
|
||||||
print("222")
|
print('music handler started')
|
||||||
print(status)
|
|
||||||
if status == 200:
|
if status == 200:
|
||||||
navidromePlaylistSync.start()
|
navidromePlaylistSync.start()
|
||||||
|
|
||||||
|
headers['Transfer-Encoding'] = 'gzip'
|
||||||
return [response, headers, status, content]
|
return [response, headers, status, content]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,10 +1,12 @@
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
host = 'http://192.168.124.12:4533'
|
||||||
|
|
||||||
def getPlaylist(token):
|
def getPlaylist(token):
|
||||||
headers = {
|
headers = {
|
||||||
'x-nd-authorization': f'Bearer {token}'
|
'x-nd-authorization': f'Bearer {token}'
|
||||||
}
|
}
|
||||||
res = requests.get('https://music.hiiragi.club:8081/api/playlist?_end=50&_order=ASC&_sort=id&_start=0', headers = headers)
|
res = requests.get(f'{host}/music/api/playlist?_end=50&_order=ASC&_sort=id&_start=0', headers = headers)
|
||||||
resJson = res.json()
|
resJson = res.json()
|
||||||
return resJson
|
return resJson
|
||||||
|
|
||||||
@ -13,13 +15,13 @@ def downloadPlayList(palyListId, token):
|
|||||||
'Accept': 'audio/x-mpegurl',
|
'Accept': 'audio/x-mpegurl',
|
||||||
'x-nd-authorization': f'Bearer {token}'
|
'x-nd-authorization': f'Bearer {token}'
|
||||||
}
|
}
|
||||||
res = requests.get(f'https://music.hiiragi.club:8081/api/playlist/{palyListId}/tracks', headers = headers)
|
res = requests.get(f'{host}/music/api/playlist/{palyListId}/tracks', headers = headers)
|
||||||
return res.content
|
return res.content
|
||||||
|
|
||||||
def delPlaylist(playlistId, token):
|
def delPlaylist(playlistId, token):
|
||||||
headers = {
|
headers = {
|
||||||
'x-nd-authorization': f'Bearer {token}'
|
'x-nd-authorization': f'Bearer {token}'
|
||||||
}
|
}
|
||||||
res = requests.delete(f'https://music.hiiragi.club:8081/api/playlist/{playlistId}', headers = headers)
|
res = requests.delete(f'{host}/music/api/playlist/{playlistId}', headers = headers)
|
||||||
resJson = res.json()
|
resJson = res.json()
|
||||||
return resJson
|
return resJson
|
@ -1,7 +1,7 @@
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
def getToken():
|
def getToken():
|
||||||
body = { 'username': 'mol', 'password': 'c!UxnePTkwBMb7' }
|
body = { 'username': 'fan@yunying.com', 'password': 'm%Bn$w5jgiNsNC' }
|
||||||
res = requests.post('https://music.hiiragi.club:8081/auth/login', json = body)
|
res = requests.post('http://192.168.124.12:4533/music/auth/login', json = body)
|
||||||
resJson = res.json()
|
resJson = res.json()
|
||||||
return resJson.get('token')
|
return resJson.get('token')
|
@ -1,28 +1,30 @@
|
|||||||
import os
|
import os
|
||||||
from webdav3.client import Client
|
from webdav3.client import Client
|
||||||
from webdav3.exceptions import LocalResourceNotFound, RemoteResourceNotFound
|
from webdav3.exceptions import LocalResourceNotFound, RemoteResourceNotFound, ResponseErrorCode
|
||||||
|
|
||||||
def sync():
|
def sync():
|
||||||
options = {
|
options = {
|
||||||
'webdav_hostname': 'https://pan.hiiragi.club:8081/dav',
|
'webdav_hostname': 'https://pan.liliyamol.cn/webdav/',
|
||||||
'webdav_login': 'mol',
|
'webdav_login': 'fan@yunying.com',
|
||||||
'webdav_password': 'YvG4SkF82qd7ks',
|
'webdav_password': 'm%Bn$w5jgiNsNC',
|
||||||
'disable_check': True,
|
'disable_check': True,
|
||||||
}
|
}
|
||||||
|
|
||||||
client = Client(options)
|
client = Client(options)
|
||||||
tempPath = os.path.join(os.path.dirname(__file__), 'temp')
|
tempPath = os.path.join(os.path.dirname(__file__), 'temp')
|
||||||
playlists = os.listdir(tempPath)
|
playlists = os.listdir(tempPath)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
client.clean('Music/#playlist')
|
client.clean('Music/#playlist')
|
||||||
except RemoteResourceNotFound as exception:
|
except RemoteResourceNotFound as exception:
|
||||||
print('clean failed!')
|
print('clean failed!')
|
||||||
|
except ResponseErrorCode as exception:
|
||||||
for fileName in playlists:
|
print('error')
|
||||||
path = os.path.join(tempPath, fileName)
|
|
||||||
try:
|
for fileName in playlists:
|
||||||
client.upload('Music/#playlist/' + fileName, path)
|
path = os.path.join(tempPath, fileName)
|
||||||
print(fileName + ' upload success!!')
|
try:
|
||||||
except LocalResourceNotFound as exception:
|
client.upload('Music/#playlist/' + fileName, path)
|
||||||
|
print(fileName + ' upload success!!')
|
||||||
|
except LocalResourceNotFound as exception:
|
||||||
print(fileName + ' upload failed!!')
|
print(fileName + ' upload failed!!')
|
@ -1,3 +0,0 @@
|
|||||||
#EXTM3U
|
|
||||||
#EXTINF:317,浮森かや子 - お隣はだあれ
|
|
||||||
/music/浮森かや子/お隣はだあれ.mp3
|
|
@ -1 +0,0 @@
|
|||||||
#EXTM3U
|
|
Binary file not shown.
Binary file not shown.
5
requirements.txt
Normal file
5
requirements.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
gunicorn
|
||||||
|
gevent
|
||||||
|
flask
|
||||||
|
requests
|
||||||
|
webdavclient3
|
@ -17,7 +17,7 @@ class GatewayServer():
|
|||||||
"service_name": "music_server",
|
"service_name": "music_server",
|
||||||
"methods": ["POST"],
|
"methods": ["POST"],
|
||||||
"path": "/music/api/playlist/<playlist_id>/tracks",
|
"path": "/music/api/playlist/<playlist_id>/tracks",
|
||||||
"upstream_path": "/api/playlist/<playlist_id>/tracks",
|
"upstream_path": "/music/api/playlist/<playlist_id>/tracks",
|
||||||
"pipelines": {
|
"pipelines": {
|
||||||
"outbound": [{ "name": "plugin.MusicHandler.MusicHandler" }]
|
"outbound": [{ "name": "plugin.MusicHandler.MusicHandler" }]
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ class GatewayServer():
|
|||||||
"service_name": "music_server",
|
"service_name": "music_server",
|
||||||
"methods": ["DELETE"],
|
"methods": ["DELETE"],
|
||||||
"path": "/music/api/playlist/<playlist_id>/tracks",
|
"path": "/music/api/playlist/<playlist_id>/tracks",
|
||||||
"upstream_path": "/api/playlist/<playlist_id>/tracks",
|
"upstream_path": "/music/api/playlist/<playlist_id>/tracks",
|
||||||
"pipelines": {
|
"pipelines": {
|
||||||
"outbound": [{ "name": "plugin.MusicHandler.MusicHandler" }]
|
"outbound": [{ "name": "plugin.MusicHandler.MusicHandler" }]
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ class GatewayServer():
|
|||||||
"service_name": "music_server",
|
"service_name": "music_server",
|
||||||
"methods": ["DELETE"],
|
"methods": ["DELETE"],
|
||||||
"path": "/music/api/playlist/<playlist_id>",
|
"path": "/music/api/playlist/<playlist_id>",
|
||||||
"upstream_path": "/api/playlist/<playlist_id>",
|
"upstream_path": "/music/api/playlist/<playlist_id>",
|
||||||
"pipelines": {
|
"pipelines": {
|
||||||
"outbound": [{ "name": "plugin.MusicHandler.MusicHandler" }]
|
"outbound": [{ "name": "plugin.MusicHandler.MusicHandler" }]
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ class GatewayServer():
|
|||||||
"service_name": "music_server",
|
"service_name": "music_server",
|
||||||
"methods": ["POST"],
|
"methods": ["POST"],
|
||||||
"path": "/music/api/playlist",
|
"path": "/music/api/playlist",
|
||||||
"upstream_path": "/api/playlist",
|
"upstream_path": "/music/api/playlist",
|
||||||
"pipelines": {
|
"pipelines": {
|
||||||
"outbound": [{ "name": "plugin.MusicHandler.MusicHandler" }]
|
"outbound": [{ "name": "plugin.MusicHandler.MusicHandler" }]
|
||||||
}
|
}
|
||||||
@ -63,4 +63,7 @@ class GatewayServer():
|
|||||||
|
|
||||||
gateway_server = GatewayServer()
|
gateway_server = GatewayServer()
|
||||||
app = gateway_server.app
|
app = gateway_server.app
|
||||||
app.run(port=5000, debug=True)
|
# app.run(port=15000, host="192.168.124.12", debug=True)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(debug=True)
|
24
test2.py
24
test2.py
@ -1,24 +0,0 @@
|
|||||||
from flask import Flask
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
|
|
||||||
@app.route("/api/tracks")
|
|
||||||
def hello_tracks():
|
|
||||||
return "<p>Hello, tracks!</p>"
|
|
||||||
|
|
||||||
@app.route("/api/playlist/<playlist_id>/tracks")
|
|
||||||
def hello_playlist():
|
|
||||||
return "<p>Hello, playlist!</p>"
|
|
||||||
|
|
||||||
app.run(
|
|
||||||
host = '127.0.0.1',
|
|
||||||
port = 7777,
|
|
||||||
debug = True
|
|
||||||
)
|
|
||||||
|
|
||||||
if __name__== '__main__':
|
|
||||||
app.run(
|
|
||||||
host = '127.0.0.1',
|
|
||||||
port = 7777,
|
|
||||||
debug = True
|
|
||||||
)
|
|
Reference in New Issue
Block a user