Compare commits
3 Commits
a2f1b6d4fd
...
15885c5676
Author | SHA1 | Date | |
---|---|---|---|
15885c5676 | |||
a2caaddef4 | |||
8f884cc352 |
62
.drone.yml
Normal file
62
.drone.yml
Normal file
@ -0,0 +1,62 @@
|
||||
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
|
||||
registry: https://git.hiiragi.club:8081
|
||||
repo: git.hiiragi.club:8081/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.hiiragi.club:8081
|
||||
- docker pull git.hiiragi.club:8081/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 --name=middle_server_${DRONE_TAG} git.hiiragi.club:8081/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)
|
||||
|
||||
def proxy_request(*args, **kwargs):
|
||||
|
||||
print('成功代理', route.name)
|
||||
upstream_path = route.upstream_path
|
||||
for p_name in route.upstream_params:
|
||||
v = get_params_from_context(p_name, kwargs)
|
||||
@ -79,6 +79,7 @@ class GenericGateway(object):
|
||||
if request.form:
|
||||
upstream_req_info['data'] = request.form
|
||||
|
||||
# print('upstream_req_info', upstream_req_info)
|
||||
for pipe_handler in route.inbound_pipes():
|
||||
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'].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)
|
||||
# print(resp.headers)
|
||||
status = resp.status_code
|
||||
content = None
|
||||
headers = resp.headers
|
||||
|
||||
print(route.outbound_pipes())
|
||||
for pipe_handler in route.outbound_pipes():
|
||||
resp, headers, status, content = pipe_handler(resp, headers, status, content, *args, **kwargs)
|
||||
|
||||
content = make_response(content or resp.content)
|
||||
for h_name, h_value in (headers or {}).items():
|
||||
# print(h_name, h_value)
|
||||
content.headers[h_name] = h_value
|
||||
|
||||
# print('content', headers)
|
||||
return content, status
|
||||
|
||||
# 修改函数名称:Flask route注册使用func name必须唯一
|
||||
proxy_request.__name__ = route.name
|
||||
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)
|
||||
"""
|
||||
# raise NotImplementedError
|
||||
print("222")
|
||||
print(status)
|
||||
print('music handler started')
|
||||
if status == 200:
|
||||
navidromePlaylistSync.start()
|
||||
|
||||
headers['Transfer-Encoding'] = 'gzip'
|
||||
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
|
||||
|
||||
host = 'http://192.168.124.12:4533'
|
||||
|
||||
def getPlaylist(token):
|
||||
headers = {
|
||||
'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()
|
||||
return resJson
|
||||
|
||||
@ -13,13 +15,13 @@ def downloadPlayList(palyListId, token):
|
||||
'Accept': 'audio/x-mpegurl',
|
||||
'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
|
||||
|
||||
def delPlaylist(playlistId, token):
|
||||
headers = {
|
||||
'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()
|
||||
return resJson
|
@ -2,6 +2,6 @@ import requests
|
||||
|
||||
def getToken():
|
||||
body = { 'username': 'mol', 'password': 'c!UxnePTkwBMb7' }
|
||||
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()
|
||||
return resJson.get('token')
|
@ -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",
|
||||
"methods": ["POST"],
|
||||
"path": "/music/api/playlist/<playlist_id>/tracks",
|
||||
"upstream_path": "/api/playlist/<playlist_id>/tracks",
|
||||
"upstream_path": "/music/api/playlist/<playlist_id>/tracks",
|
||||
"pipelines": {
|
||||
"outbound": [{ "name": "plugin.MusicHandler.MusicHandler" }]
|
||||
}
|
||||
@ -28,7 +28,7 @@ class GatewayServer():
|
||||
"service_name": "music_server",
|
||||
"methods": ["DELETE"],
|
||||
"path": "/music/api/playlist/<playlist_id>/tracks",
|
||||
"upstream_path": "/api/playlist/<playlist_id>/tracks",
|
||||
"upstream_path": "/music/api/playlist/<playlist_id>/tracks",
|
||||
"pipelines": {
|
||||
"outbound": [{ "name": "plugin.MusicHandler.MusicHandler" }]
|
||||
}
|
||||
@ -39,7 +39,7 @@ class GatewayServer():
|
||||
"service_name": "music_server",
|
||||
"methods": ["DELETE"],
|
||||
"path": "/music/api/playlist/<playlist_id>",
|
||||
"upstream_path": "/api/playlist/<playlist_id>",
|
||||
"upstream_path": "/music/api/playlist/<playlist_id>",
|
||||
"pipelines": {
|
||||
"outbound": [{ "name": "plugin.MusicHandler.MusicHandler" }]
|
||||
}
|
||||
@ -50,7 +50,7 @@ class GatewayServer():
|
||||
"service_name": "music_server",
|
||||
"methods": ["POST"],
|
||||
"path": "/music/api/playlist",
|
||||
"upstream_path": "/api/playlist",
|
||||
"upstream_path": "/music/api/playlist",
|
||||
"pipelines": {
|
||||
"outbound": [{ "name": "plugin.MusicHandler.MusicHandler" }]
|
||||
}
|
||||
@ -63,4 +63,7 @@ class GatewayServer():
|
||||
|
||||
gateway_server = GatewayServer()
|
||||
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