Skip to content

Commit

Permalink
添加mysql端口和静态资源host配置功能
Browse files Browse the repository at this point in the history
  • Loading branch information
MK committed Mar 24, 2019
1 parent 001dc53 commit 775a1bd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
17 changes: 12 additions & 5 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@
FILE_FOLDER = os.path.join(DOWNLOAD_FOLDER, 'file')
VIDEO_FOLDER = os.path.join(DOWNLOAD_FOLDER, 'video')

LOCAL_AUDIO_BASE_URL = 'http://127.0.0.1:8000/%s/' % 'download/audios'
LOCAL_IMG_BASE_URL = 'http://127.0.0.1:8000/%s/' % 'download/images'
LOCAL_FILE_BASE_URL = 'http://127.0.0.1:8000/%s/' % 'download/file'
LOCAL_VIDEO_BASE_URL = 'http://127.0.0.1:8000/%s/' % 'download/video'
LOCAL_SERVER_HOST = '127.0.0.1'
LOCAL_SERVER_PORT = 8000

WEB_SERVER_HOST = '0.0.0.0'
WEB_SERVER_PORT = 8080

LOCAL_BASE_URL = 'http://{}:{}/'.format(LOCAL_SERVER_HOST, LOCAL_SERVER_PORT)
LOCAL_AUDIO_BASE_URL = LOCAL_BASE_URL + 'download/audios/'
LOCAL_IMG_BASE_URL = LOCAL_BASE_URL + 'download/images/'
LOCAL_FILE_BASE_URL = LOCAL_BASE_URL + 'download/file/'
LOCAL_VIDEO_BASE_URL = LOCAL_BASE_URL + 'download/video/'

for x in [DOWNLOAD_FOLDER, IMAGE_FOLDER, AUDIO_FOLDER, FILE_FOLDER, VIDEO_FOLDER]:
if not os.path.exists(x):
Expand All @@ -40,8 +47,8 @@
BAIDU_TOKEN_URL = 'https://openapi.baidu.com/oauth/2.0/token'
BAIDU_SERVER_URL = 'http://vop.baidu.com/server_api'


DB_HOST = '192.168.56.128'
DB_PORT = 60610

This comment has been minimized.

Copy link
@m4wayne

m4wayne Mar 25, 2019

Contributor

抱歉,提交时此处忘记改成mysql默认端口3306。

This comment has been minimized.

Copy link
@m4wayne

m4wayne Mar 25, 2019

Contributor

后期哪位更新代码,麻烦把60610改成3306,谢谢

DB_NAME = 'zhihu'
DB_USER = 'zhihu'
DB_PASS = 'password'
Expand Down
3 changes: 2 additions & 1 deletion download/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from http.server import SimpleHTTPRequestHandler

import config

def copy_byte_range(infile, outfile, start=None, stop=None, bufsize=16*1024):
'''Like shutil.copyfileobj, but only copy a range of the streams.
Expand Down Expand Up @@ -112,7 +113,7 @@ def copyfile(self, source, outputfile):
copy_byte_range(source, outputfile, start, stop)


def run(port=8000):
def run(port=config.LOCAL_SERVER_PORT):
SimpleHTTPServer.test(HandlerClass=RangeRequestHandler, port=port)


Expand Down
2 changes: 1 addition & 1 deletion models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from itertools import chain

database = peewee_async.MySQLDatabase(host=config.DB_HOST, database=config.DB_NAME, password=config.DB_PASS,
user=config.DB_USER, charset='utf8mb4')
user=config.DB_USER, port=config.DB_PORT, charset='utf8mb4')


class BaseModel(peewee.Model):
Expand Down
3 changes: 2 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from web.main import app
from download.main import run as media_server

import config

@click.group()
def cli():
Expand Down Expand Up @@ -66,7 +67,7 @@ def webserver():
click.echo('Start web server')
threading.Thread(target=media_server, args=()).start()
app.router.add_static('/static', 'web/static')
web.run_app(app)
web.run_app(app, host=config.WEB_SERVER_HOST, port=config.WEB_SERVER_PORT)


cli.add_command(initdb)
Expand Down

0 comments on commit 775a1bd

Please sign in to comment.