Example #1
0
def youtube_upload():
	path = check_string(request, params.PATH)
	
	if not check_path(path):
		path = None	
	
	if path == None:
		return send_error(error_codes.INVALID_PATH, "You need to specify path parameter")
	if not os.path.isdir(path):
		return send_no_dir_error(path)

	url = check_string(request, params.URL)
	if url == None:
		return send_error(error_codes.INVALID_URL, "You need to specify URL parameter")

	threaded = check_boolean(request, params.THREADED)

	if threaded:
		thread = threading.Thread(target = explorer.downloadYouTube, args = (path, url))
		thread.daemon = True
		thread.start()
	else:
		explorer.downloadYouTube(path, url)

	return jsonify({
			"code" : error_codes.SUCCESFULL_QUERY,
			"message" : "Query has been dispatched"
		})
Example #2
0
def create_catalog():
	path = check_string(request, params.PATH)
	name = check_string(request, params.NAME)

	if not check_path(path):
		path = None

	if path == None:
		return send_error(error_codes.INVALID_PATH, "You need to specify path parameter")
	if not os.path.isdir(path):
		return send_no_dir_error(path)
	if name == "":
		return jsonify({
				"code" : error_codes.INVALID_CATALOG_NAME,
				"message" : "Invalid name"
			})	 

	final_path = os.path.join(path, name)
	if os.path.isdir(final_path):
		return jsonify({
				"code" : error_codes.DATA_MANAGEMENT_ERROR,
				"message" : "Folder already exsists."
			})

	try:
		os.mkdir(final_path)
		return jsonify({
				"code" : error_codes.SUCCESFULL_QUERY,
				"message" : "Folder succesfully created"
			})
	except:
		return jsonify({
				"code" : error_codes.DATA_MANAGEMENT_ERROR,
				"message" : "An error has occured."
			})
Example #3
0
def file_upload():
	path = check_string(request, params.PATH)
	
	if not check_path(path):
		path = None	
	
	if path == None:
		return send_error(error_codes.INVALID_PATH, "You need to specify path parameter")
	if not os.path.isdir(path):
		return send_no_dir_error(path)

	file = request.files['file']
	if file and allowed_file(file.filename):
		filename = secure_filename(file.filename)
		file_path = os.path.join(path, filename)
		file.save(file_path)
		return jsonify({
			"code" : error_codes.SUCCESFULL_QUERY,
			"path" : file_path,
			"message" : "File uploaded"
			})

	return jsonify({
			"code" : error_codes.UNALLOWED_EXTENSION,
			"message" : "Unallowed extension"
		})