youtube-dl-webui icon indicating copy to clipboard operation
youtube-dl-webui copied to clipboard

baseurl option for working with reverse proxies

Open hariseldon99 opened this issue 3 years ago • 2 comments

Any thoughts on adding an option to change the baseurl? I ask because it'd be cool if this could work with reverse proxies like nginx

hariseldon99 avatar Sep 07 '20 11:09 hariseldon99

:+1: I've been annoyed by this as well, I made a quick dirty patch to the code to support my static prefix.

Spoiler: Super dirty yolo code edit: Nginx config:
    location /iamapig/ {
         # [...]
         proxy_pass http://10.1.2.3:5000;
    }

Ugly code diff: python + js

diff --git a/youtube_dl_webui/server.py b/youtube_dl_webui/server.py
index 62d0b3d..08a89af 100644
--- a/youtube_dl_webui/server.py
+++ b/youtube_dl_webui/server.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import json
@@ -8,19 +8,20 @@ from flask import render_template
from flask import request
from multiprocessing import Process
from copy import deepcopy

MSG = None
-
-app = Flask(__name__)
+URL_PREFIX="iamapig"
+app = Flask(__name__, static_url_path="{}/static".format(URL_PREFIX))

MSG_INVALID_REQUEST = {'status': 'error', 'errmsg': 'invalid request'}

[email protected]('/')
[email protected](URL_PREFIX + '/')
def index():
   return render_template('index.html')


[email protected]('/task', methods=['POST'])
[email protected](URL_PREFIX + '/task', methods=['POST'])
def add_task():
   payload = request.get_json()

@@ -28,7 +29,7 @@ def add_task():
   return json.dumps(MSG.get())


[email protected]('/task/list', methods=['GET'])
[email protected](URL_PREFIX + '/task/list', methods=['GET'])
def list_task():
   payload = {}
   exerpt = request.args.get('exerpt', None)
@@ -43,20 +44,20 @@ def list_task():
   return json.dumps(MSG.get())


[email protected]('/task/state_counter', methods=['GET'])
[email protected](URL_PREFIX + '/task/state_counter', methods=['GET'])
def list_state():
   MSG.put('state', None)
   return json.dumps(MSG.get())


[email protected]('/task/batch/<action>', methods=['POST'])
[email protected](URL_PREFIX + '/task/batch/<action>', methods=['POST'])
def task_batch(action):
   payload={'act': action, 'detail': request.get_json()}

   MSG.put('batch', payload)
   return json.dumps(MSG.get())

[email protected]('/task/tid/<tid>', methods=['DELETE'])
[email protected](URL_PREFIX + '/task/tid/<tid>', methods=['DELETE'])
def delete_task(tid):
   del_flag = request.args.get('del_file', False)
   payload = {}
@@ -67,7 +68,7 @@ def delete_task(tid):
   return json.dumps(MSG.get())


[email protected]('/task/tid/<tid>', methods=['PUT'])
[email protected](URL_PREFIX + '/task/tid/<tid>', methods=['PUT'])
def manipulate_task(tid):
   payload = {}
   payload['tid'] = tid
@@ -84,7 +85,7 @@ def manipulate_task(tid):
   return json.dumps(MSG.get())


[email protected]('/task/tid/<tid>/status', methods=['GET'])
[email protected](URL_PREFIX + '/task/tid/<tid>/status', methods=['GET'])
def query_task(tid):
   payload = {}
   payload['tid'] = tid
@@ -99,7 +100,7 @@ def query_task(tid):
   return json.dumps(MSG.get())


[email protected]('/config', methods=['GET', 'POST'])
[email protected](URL_PREFIX + '/config', methods=['GET', 'POST'])
def get_config():
   payload = {}
   if request.method == 'POST':
@@ -115,7 +116,7 @@ def get_config():
###
# test cases
###
[email protected]('/test/<case>')
[email protected](URL_PREFIX + '/test/<case>')
def test(case):
   return render_template('test/{}.html'.format(case))

@@ -134,4 +135,3 @@ class Server(Process):
       MSG = self.msg_cli
       app.run(host=self.host, port=int(self.port), use_reloader=False)

-
diff --git a/youtube_dl_webui/static/js/global.js b/youtube_dl_webui/static/js/global.js
index 7d5935b..4f6e329 100644
--- a/youtube_dl_webui/static/js/global.js
+++ b/youtube_dl_webui/static/js/global.js
@@ -3,7 +3,7 @@ var videoDownload = (function (Vue, extendAM){
   var VueToast = window.vueToasts ? window.vueToasts.default || window.vueToasts : window.vueToasts;
   videoDownload.vm = null;
   videoDownload.tasksData = {
-        headPath: 'http://localhost:5000/',
+        headPath: '/iamapig/',
       videoList: [],
       videoListCopy: [],
       showModal: false,
@@ -293,7 +293,7 @@ var videoDownload = (function (Vue, extendAM){

   videoDownload.init = function(){
       var that = this;
-        that.tasksData.headPath = window.location.protocol + '//' + window.location.host + '/';
+        that.tasksData.headPath = window.location.protocol + '//' + window.location.host + '/iamapig/';
       that.createVm();
       that.getTaskList();
   }

thomsh avatar Jan 18 '21 09:01 thomsh

Hi,

I'm in the same situation.

Can you please make a PR of your changes?

Thanks

floviolleau avatar Mar 31 '21 12:03 floviolleau