mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2025-12-03 22:55:33 +00:00
API - Import - Automatically assume text/plain content type on Import (makes it easier for changedetection to add new URLs) #3547 #3542
This commit is contained in:
@@ -3,15 +3,30 @@ from changedetectionio.strtobool import strtobool
|
|||||||
from flask_restful import abort, Resource
|
from flask_restful import abort, Resource
|
||||||
from flask import request
|
from flask import request
|
||||||
import validators
|
import validators
|
||||||
|
from functools import wraps
|
||||||
from . import auth, validate_openapi_request
|
from . import auth, validate_openapi_request
|
||||||
|
|
||||||
|
|
||||||
|
def default_content_type(content_type='text/plain'):
|
||||||
|
"""Decorator to set a default Content-Type header if none is provided."""
|
||||||
|
def decorator(f):
|
||||||
|
@wraps(f)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
if not request.content_type:
|
||||||
|
# Set default content type in the request environment
|
||||||
|
request.environ['CONTENT_TYPE'] = content_type
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
return wrapper
|
||||||
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
class Import(Resource):
|
class Import(Resource):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
# datastore is a black box dependency
|
# datastore is a black box dependency
|
||||||
self.datastore = kwargs['datastore']
|
self.datastore = kwargs['datastore']
|
||||||
|
|
||||||
@auth.check_token
|
@auth.check_token
|
||||||
|
@default_content_type('text/plain') #3547 #3542
|
||||||
@validate_openapi_request('importWatches')
|
@validate_openapi_request('importWatches')
|
||||||
def post(self):
|
def post(self):
|
||||||
"""Import a list of watched URLs."""
|
"""Import a list of watched URLs."""
|
||||||
|
|||||||
Reference in New Issue
Block a user