Add set_queuefile_extension method, endpoint, and ui.
This commit is contained in:
		
							parent
							
								
									223d3d01fb
								
							
						
					
					
						commit
						741cddc2e4
					
				
					 4 changed files with 57 additions and 0 deletions
				
			
		|  | @ -134,3 +134,12 @@ def post_set_automark(channel_id): | ||||||
|         flask.abort(400) |         flask.abort(400) | ||||||
| 
 | 
 | ||||||
|     return jsonify.make_json_response({}) |     return jsonify.make_json_response({}) | ||||||
|  | 
 | ||||||
|  | @site.route('/channel/<channel_id>/set_queuefile_extension', methods=['POST']) | ||||||
|  | def post_set_queuefile_extension(channel_id): | ||||||
|  |     extension = request.form['extension'] | ||||||
|  |     channel = common.ycdldb.get_channel(channel_id) | ||||||
|  | 
 | ||||||
|  |     channel.set_queuefile_extension(extension) | ||||||
|  | 
 | ||||||
|  |     return jsonify.make_json_response({}) | ||||||
|  |  | ||||||
|  | @ -47,6 +47,15 @@ function set_automark(channel_id, state, callback) | ||||||
|     return common.post(url, data, callback); |     return common.post(url, data, callback); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | api.channels.set_queuefile_extension = | ||||||
|  | function set_queuefile_extension(channel_id, extension, callback) | ||||||
|  | { | ||||||
|  |     const url = `/channel/${channel_id}/set_queuefile_extension`; | ||||||
|  |     const data = new FormData(); | ||||||
|  |     data.append("extension", extension); | ||||||
|  |     return common.post(url, data, callback); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| api.channels.callback_go_to_channels = | api.channels.callback_go_to_channels = | ||||||
| function callback_go_to_channels(response) | function callback_go_to_channels(response) | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -265,6 +265,11 @@ https://stackoverflow.com/a/35153397 | ||||||
|         <span id="set_automark_spinner" class="hidden">Working...</span> |         <span id="set_automark_spinner" class="hidden">Working...</span> | ||||||
|     </div> |     </div> | ||||||
| 
 | 
 | ||||||
|  |     <div> | ||||||
|  |         <input type="text" id="set_queuefile_extension_input" placeholder="Queuefile extension" value="{{channel.queuefile_extension or ''}}"/> | ||||||
|  |         <button id="set_queuefile_extension_button" class="button_with_spinner" onclick="return set_queuefile_extension_form();">Set extension</button> | ||||||
|  |     </div> | ||||||
|  | 
 | ||||||
|     <button class="red_button button_with_confirm" |     <button class="red_button button_with_confirm" | ||||||
|     data-prompt="Delete channel and all videos?" |     data-prompt="Delete channel and all videos?" | ||||||
|     data-onclick="return delete_channel_form();" |     data-onclick="return delete_channel_form();" | ||||||
|  | @ -540,5 +545,22 @@ function set_automark_callback(response) | ||||||
|         set_automark_spinner.hide(); |         set_automark_spinner.hide(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | set_queuefile_extension_input = document.getElementById("set_queuefile_extension_input"); | ||||||
|  | set_queuefile_extension_button = document.getElementById("set_queuefile_extension_button"); | ||||||
|  | common.bind_box_to_button(set_queuefile_extension_input, set_queuefile_extension_button); | ||||||
|  | function set_queuefile_extension_form(event) | ||||||
|  | { | ||||||
|  |     const extension = set_queuefile_extension_input.value.trim(); | ||||||
|  |     api.channels.set_queuefile_extension(CHANNEL_ID, extension, set_queuefile_extension_callback); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function set_queuefile_extension_callback(response) | ||||||
|  | { | ||||||
|  |     if (response.meta.status == 200) | ||||||
|  |     { | ||||||
|  |         window[set_queuefile_extension_button.dataset.spinnerCloser](); | ||||||
|  |     } | ||||||
|  | } | ||||||
| </script> | </script> | ||||||
| </html> | </html> | ||||||
|  |  | ||||||
|  | @ -80,6 +80,23 @@ class Channel(Base): | ||||||
|         if commit: |         if commit: | ||||||
|             self.ycdldb.commit() |             self.ycdldb.commit() | ||||||
| 
 | 
 | ||||||
|  |     def set_queuefile_extension(self, extension, commit=True): | ||||||
|  |         if not extension: | ||||||
|  |             extension = None | ||||||
|  | 
 | ||||||
|  |         if extension is not None: | ||||||
|  |             extension = extension.strip() | ||||||
|  | 
 | ||||||
|  |         pairs = { | ||||||
|  |             'id': self.id, | ||||||
|  |             'queuefile_extension': extension, | ||||||
|  |         } | ||||||
|  |         self.ycdldb.sql_update(table='channels', pairs=pairs, where_key='id') | ||||||
|  |         self.queuefile_extension = extension | ||||||
|  | 
 | ||||||
|  |         if commit: | ||||||
|  |             self.ycdldb.commit() | ||||||
|  | 
 | ||||||
|     def set_uploads_playlist_id(self, playlist_id, commit=True): |     def set_uploads_playlist_id(self, playlist_id, commit=True): | ||||||
|         if not isinstance(playlist_id, str): |         if not isinstance(playlist_id, str): | ||||||
|             raise TypeError(f'Playlist id must be a string, not {type(playlist_id)}.') |             raise TypeError(f'Playlist id must be a string, not {type(playlist_id)}.') | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue