From 408c8878f3cdfed79de18c5eedadbd76db7a1295 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Thu, 19 May 2022 18:08:15 +0200 Subject: [PATCH] bump old old API --- changedetectionio/__init__.py | 23 +---------------------- changedetectionio/api_v1.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index 44b8710f..194729c7 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -185,7 +185,7 @@ def changedetection_app(config=None, datastore_o=None): watch_api.add_resource(api_v1.WatchSingleHistory, - '/api/v1/watch//history/', + '/api/v1/watch//history/', resource_class_kwargs={'datastore': datastore, 'update_q': update_q}) watch_api.add_resource(api_v1.WatchHistory, @@ -894,27 +894,6 @@ def changedetection_app(config=None, datastore_o=None): return output - @app.route("/api//snapshot/current", methods=['GET']) - @login_required - def api_snapshot(uuid): - - # More for testing, possible to return the first/only - if uuid == 'first': - uuid = list(datastore.data['watching'].keys()).pop() - - try: - watch = datastore.data['watching'][uuid] - except KeyError: - return abort(400, "No history found for the specified link, bad link?") - - newest = list(watch['history'].keys())[-1] - with open(watch['history'][newest], 'r') as f: - content = f.read() - - resp = make_response(content) - resp.headers['Content-Type'] = 'text/plain' - return resp - @app.route("/favicon.ico", methods=['GET']) def favicon(): return send_from_directory("static/images", path="favicon.ico") diff --git a/changedetectionio/api_v1.py b/changedetectionio/api_v1.py index 91e62c45..6094fa87 100644 --- a/changedetectionio/api_v1.py +++ b/changedetectionio/api_v1.py @@ -53,19 +53,23 @@ class WatchSingleHistory(Resource): # datastore is a black box dependency self.datastore = kwargs['datastore'] + # Read a given history snapshot and return its content + # or "latest" + # curl http://localhost:4000/api/v1/watch//history/ def get(self, uuid, timestamp): watch = self.datastore.data['watching'].get(uuid) if not watch: abort(404, message='No watch exists with the UUID of {}'.format(uuid)) - return watch + if not len(watch['history']): + abort(404, message='Watch found but no history exists for the UUID {}'.format(uuid)) - def delete(self, uuid, timestamp): - if not self.datastore.data['watching'].get(uuid): - abort(400, message='No watch exists with the UUID of {}'.format(uuid)) + if timestamp == 'latest': + timestamp = list(watch['history'].keys())[-1] - self.datastore.delete(uuid) - return '', 204 + with open(watch['history'][timestamp], 'r') as f: + content = f.read() + return content, '200', {'Content-type': 'text/plain'} class CreateWatch(Resource):