Move endpoints into separate files like Etiquette.
This commit is contained in:
		
							parent
							
								
									13a72ec7fc
								
							
						
					
					
						commit
						21af1576c2
					
				
					 4 changed files with 77 additions and 60 deletions
				
			
		
							
								
								
									
										3
									
								
								frontends/ycdl_flask/backend/endpoints/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								frontends/ycdl_flask/backend/endpoints/__init__.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | ||||||
|  | from . import basic_endpoints | ||||||
|  | from . import channel_endpoints | ||||||
|  | from . import video_endpoints | ||||||
							
								
								
									
										14
									
								
								frontends/ycdl_flask/backend/endpoints/basic_endpoints.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								frontends/ycdl_flask/backend/endpoints/basic_endpoints.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,14 @@ | ||||||
|  | import flask; from flask import request | ||||||
|  | 
 | ||||||
|  | from .. import common | ||||||
|  | 
 | ||||||
|  | site = common.site | ||||||
|  | 
 | ||||||
|  | @site.route('/') | ||||||
|  | def root(): | ||||||
|  |     return flask.render_template('root.html') | ||||||
|  | 
 | ||||||
|  | @site.route('/favicon.ico') | ||||||
|  | @site.route('/favicon.png') | ||||||
|  | def favicon(): | ||||||
|  |     return flask.send_file(common.FAVICON_PATH.absolute_path) | ||||||
|  | @ -4,20 +4,11 @@ import traceback | ||||||
| 
 | 
 | ||||||
| import ycdl | import ycdl | ||||||
| 
 | 
 | ||||||
| from . import common | from .. import common | ||||||
| from . import jsonify | from .. import jsonify | ||||||
| 
 | 
 | ||||||
| site = common.site | site = common.site | ||||||
| 
 | 
 | ||||||
| @site.route('/') |  | ||||||
| def root(): |  | ||||||
|     return flask.render_template('root.html') |  | ||||||
| 
 |  | ||||||
| @site.route('/favicon.ico') |  | ||||||
| @site.route('/favicon.png') |  | ||||||
| def favicon(): |  | ||||||
|     return flask.send_file(common.FAVICON_PATH.absolute_path) |  | ||||||
| 
 |  | ||||||
| @site.route('/channels') | @site.route('/channels') | ||||||
| def get_channels(): | def get_channels(): | ||||||
|     channels = common.ycdldb.get_channels() |     channels = common.ycdldb.get_channels() | ||||||
|  | @ -80,37 +71,6 @@ def get_channel(channel_id=None, download_filter=None): | ||||||
|         videos=videos, |         videos=videos, | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
| @site.route('/mark_video_state', methods=['POST']) |  | ||||||
| def post_mark_video_state(): |  | ||||||
|     if 'video_ids' not in request.form or 'state' not in request.form: |  | ||||||
|         flask.abort(400) |  | ||||||
|     video_ids = request.form['video_ids'] |  | ||||||
|     state = request.form['state'] |  | ||||||
|     try: |  | ||||||
|         video_ids = video_ids.split(',') |  | ||||||
|         for video_id in video_ids: |  | ||||||
|             video = common.ycdldb.get_video(video_id) |  | ||||||
|             video.mark_state(state, commit=False) |  | ||||||
|         common.ycdldb.sql.commit() |  | ||||||
| 
 |  | ||||||
|     except ycdl.exceptions.NoSuchVideo: |  | ||||||
|         common.ycdldb.rollback() |  | ||||||
|         traceback.print_exc() |  | ||||||
|         flask.abort(404) |  | ||||||
| 
 |  | ||||||
|     except ycdl.exceptions.InvalidVideoState: |  | ||||||
|         common.ycdldb.rollback() |  | ||||||
|         flask.abort(400) |  | ||||||
| 
 |  | ||||||
|     return jsonify.make_json_response({'video_ids': video_ids, 'state': state}) |  | ||||||
| 
 |  | ||||||
| @site.route('/refresh_all_channels', methods=['POST']) |  | ||||||
| def post_refresh_all_channels(): |  | ||||||
|     force = request.form.get('force', False) |  | ||||||
|     force = ycdl.helpers.truthystring(force) |  | ||||||
|     common.ycdldb.refresh_all_channels(force=force) |  | ||||||
|     return jsonify.make_json_response({}) |  | ||||||
| 
 |  | ||||||
| @site.route('/refresh_channel', methods=['POST']) | @site.route('/refresh_channel', methods=['POST']) | ||||||
| def post_refresh_channel(): | def post_refresh_channel(): | ||||||
|     if 'channel_id' not in request.form: |     if 'channel_id' not in request.form: | ||||||
|  | @ -132,6 +92,13 @@ def post_refresh_channel(): | ||||||
|     channel.refresh(force=force) |     channel.refresh(force=force) | ||||||
|     return jsonify.make_json_response({}) |     return jsonify.make_json_response({}) | ||||||
| 
 | 
 | ||||||
|  | @site.route('/refresh_all_channels', methods=['POST']) | ||||||
|  | def post_refresh_all_channels(): | ||||||
|  |     force = request.form.get('force', False) | ||||||
|  |     force = ycdl.helpers.truthystring(force) | ||||||
|  |     common.ycdldb.refresh_all_channels(force=force) | ||||||
|  |     return jsonify.make_json_response({}) | ||||||
|  | 
 | ||||||
| @site.route('/channel/<channel_id>/set_automark', methods=['POST']) | @site.route('/channel/<channel_id>/set_automark', methods=['POST']) | ||||||
| def post_set_automark(channel_id): | def post_set_automark(channel_id): | ||||||
|     state = request.form['state'] |     state = request.form['state'] | ||||||
|  | @ -139,24 +106,7 @@ def post_set_automark(channel_id): | ||||||
| 
 | 
 | ||||||
|     try: |     try: | ||||||
|         channel.set_automark(state) |         channel.set_automark(state) | ||||||
|     except exceptions.InvalidVideoState: |     except ycdl.exceptions.InvalidVideoState: | ||||||
|         flask.abort(400) |         flask.abort(400) | ||||||
| 
 | 
 | ||||||
|     return jsonify.make_json_response({}) |     return jsonify.make_json_response({}) | ||||||
| 
 |  | ||||||
| @site.route('/start_download', methods=['POST']) |  | ||||||
| def post_start_download(): |  | ||||||
|     if 'video_ids' not in request.form: |  | ||||||
|         flask.abort(400) |  | ||||||
|     video_ids = request.form['video_ids'] |  | ||||||
|     try: |  | ||||||
|         video_ids = video_ids.split(',') |  | ||||||
|         for video_id in video_ids: |  | ||||||
|             common.ycdldb.download_video(video_id, commit=False) |  | ||||||
|         common.ycdldb.sql.commit() |  | ||||||
| 
 |  | ||||||
|     except ycdl.ytapi.VideoNotFound: |  | ||||||
|         common.ycdldb.rollback() |  | ||||||
|         flask.abort(404) |  | ||||||
| 
 |  | ||||||
|     return jsonify.make_json_response({'video_ids': video_ids, 'state': 'downloaded'}) |  | ||||||
							
								
								
									
										50
									
								
								frontends/ycdl_flask/backend/endpoints/video_endpoints.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								frontends/ycdl_flask/backend/endpoints/video_endpoints.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,50 @@ | ||||||
|  | import flask; from flask import request | ||||||
|  | import traceback | ||||||
|  | 
 | ||||||
|  | import ycdl | ||||||
|  | 
 | ||||||
|  | from .. import common | ||||||
|  | from .. import jsonify | ||||||
|  | 
 | ||||||
|  | site = common.site | ||||||
|  | 
 | ||||||
|  | @site.route('/mark_video_state', methods=['POST']) | ||||||
|  | def post_mark_video_state(): | ||||||
|  |     if 'video_ids' not in request.form or 'state' not in request.form: | ||||||
|  |         flask.abort(400) | ||||||
|  |     video_ids = request.form['video_ids'] | ||||||
|  |     state = request.form['state'] | ||||||
|  |     try: | ||||||
|  |         video_ids = video_ids.split(',') | ||||||
|  |         for video_id in video_ids: | ||||||
|  |             video = common.ycdldb.get_video(video_id) | ||||||
|  |             video.mark_state(state, commit=False) | ||||||
|  |         common.ycdldb.sql.commit() | ||||||
|  | 
 | ||||||
|  |     except ycdl.exceptions.NoSuchVideo: | ||||||
|  |         common.ycdldb.rollback() | ||||||
|  |         traceback.print_exc() | ||||||
|  |         flask.abort(404) | ||||||
|  | 
 | ||||||
|  |     except ycdl.exceptions.InvalidVideoState: | ||||||
|  |         common.ycdldb.rollback() | ||||||
|  |         flask.abort(400) | ||||||
|  | 
 | ||||||
|  |     return jsonify.make_json_response({'video_ids': video_ids, 'state': state}) | ||||||
|  | 
 | ||||||
|  | @site.route('/start_download', methods=['POST']) | ||||||
|  | def post_start_download(): | ||||||
|  |     if 'video_ids' not in request.form: | ||||||
|  |         flask.abort(400) | ||||||
|  |     video_ids = request.form['video_ids'] | ||||||
|  |     try: | ||||||
|  |         video_ids = video_ids.split(',') | ||||||
|  |         for video_id in video_ids: | ||||||
|  |             common.ycdldb.download_video(video_id, commit=False) | ||||||
|  |         common.ycdldb.sql.commit() | ||||||
|  | 
 | ||||||
|  |     except ycdl.ytapi.VideoNotFound: | ||||||
|  |         common.ycdldb.rollback() | ||||||
|  |         flask.abort(404) | ||||||
|  | 
 | ||||||
|  |     return jsonify.make_json_response({'video_ids': video_ids, 'state': 'downloaded'}) | ||||||
		Loading…
	
		Reference in a new issue