Browse Source

update tmdb/create_mapping to only accept http POST

master
cinnaboot 7 years ago
parent
commit
6c131a2ec0
  1. 25
      video_metadata/static/file_listing.js
  2. 7
      video_metadata/views/tmdb.py

25
video_metadata/static/file_listing.js

@ -87,21 +87,28 @@ function openQueryDialog(dataset) {
});
}
function submitFileMapping(click_event, movie_id, rel_path) {
async function submitFileMapping(click_event, movie_id, rel_path) {
click_event.preventDefault();
console.log('movie_id: ' + movie_id);
console.log('rel_path: ' + rel_path);
// TODO:
// - make query with POST
// - display errors
// - display success
// - update link class to file_stored
// - close query box
query_str = CREATE_MAPPING_PATH + '?movie_id=' + movie_id + '&rel_path=' + rel_path;
fetchJSON(query_str, function(json) {
query_str = CREATE_MAPPING_PATH;
params = new FormData();
params.append('movie_id', movie_id);
params.append('rel_path', rel_path);
const response = await fetch(CREATE_MAPPING_PATH, { body: params, method: 'POST' });
try {
const json = await response.json();
console.log(json);
});
} catch (e) {
logError('error in submitFileMapping(), ' + e);
}
}
function parseResponse(json, node) {
@ -166,13 +173,13 @@ function fetchJSON(url, responseFunc, node=null) {
return response.json();
})
.then(function(json) {
(node == null) ? responseFunc(json) : responseFunc(json, node);
})
// TODO: don't catch errors in responseFunc
.catch(function(error) {
logError('fetch error: ' + error);
return null;
})
.then(function(json) {
if (json != null)
(node == null) ? responseFunc(json) : responseFunc(json, node);
});
}

7
video_metadata/views/tmdb.py

@ -173,11 +173,10 @@ def query_movie_json():
# TODO: add option for tv shows
# TODO: this endpoint should be http POST only
@bp.route('/create_mapping')
@bp.route('/create_mapping', methods=['POST'])
def create_mapping():
movie_id = request.args.get('movie_id')
rel_path = request.args.get('rel_path')
movie_id = request.form['movie_id']
rel_path = request.form['rel_path']
message = ''
errors = []

Loading…
Cancel
Save