]> www.vanbest.org Git - motioneye-debian/commitdiff
fixed various bugs when changing upload services settings or provider
authorCalin Crisan <ccrisan@gmail.com>
Sat, 20 Aug 2016 17:39:46 +0000 (20:39 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Sat, 20 Aug 2016 17:39:46 +0000 (20:39 +0300)
motioneye/config.py
motioneye/static/js/main.js
motioneye/tasks.py
motioneye/uploadservices.py

index 1fb4690b1c0b1e6cb62b2b4ad91a3896bfb2d61d..fb8b9e35fb11ad3881377e3d6551da20240eccbf 100644 (file)
@@ -32,6 +32,7 @@ from tornado.ioloop import IOLoop
 import diskctl
 import powerctl
 import settings
+import tasks
 import update
 import uploadservices
 import utils
@@ -801,6 +802,8 @@ def motion_camera_ui_to_dict(ui, old_config=None):
         service.load(upload_settings)
         service.save()
 
+        tasks.add(0, uploadservices.invalidate, tag='invalidate_uploadservices', async=True)
+
     if ui['text_overlay']:
         left_text = ui['left_text']
         if left_text == 'camera-name':
index 26a2ec786c02b4d9a882d2636dfdbf4078713beb..261568239a9853de01ed6773f86fa0eaee4a4e8d 100644 (file)
@@ -2486,6 +2486,15 @@ function doTestUpload() {
     var cameraId = $('#cameraSelect').val();
 
     ajax('POST', basePath + 'config/' + cameraId + '/test/', data, function (data) {
+        /* clear the authorization key as it's definitely not usable anymore;
+         * the credentials must have already been obtained and saved */
+        $('#uploadAuthorizationKeyEntry').val('');
+        
+        /* also clear it from the pending configs dict */
+        Object.keys(pushConfigs).forEach(function (id) {
+            delete pushConfigs[id].upload_authorization_key;
+        });
+        
         hideModalDialog(); /* progress */
         if (data.error) {
             showErrorMessage('Accessing the upload service failed: ' + data.error + '!');
index e29c6367f503b9ed96d70d09c45d28741ca81411..47418e092d36166d4a99c69ba39c1419d5d44de7 100644 (file)
@@ -31,7 +31,11 @@ import settings
 _INTERVAL = 10
 _STATE_FILE_NAME = 'tasks.pickle'
 _MAX_TASKS = 100
-_POOL_SIZE = 1 # we just need one extra process to handle async tasks
+
+# we must be sure there's only one extra process
+# that handles all asynchronous tasks,
+# as we often invalidate various caches
+_POOL_SIZE = 1
 
 _tasks = []
 _pool = None
index 101029348ac8d4b11650bc65fb132fb73f30671a..5728acc28140c48e005d66341a6b30cd18ab1834 100644 (file)
@@ -169,6 +169,7 @@ class GoogleDrive(UploadService):
 
     def test_access(self):
         try:
+            self._credentials = None # invalidate credentials
             self._folder_ids = {}
             self._get_folder_id()
             return True
@@ -217,10 +218,11 @@ class GoogleDrive(UploadService):
         if 'location' in data:
             self._location = data['location']
             self._folder_ids = {}
-        if 'credentials' in data:
-            self._credentials = data['credentials']
         if 'authorization_key' in data:
             self._authorization_key = data['authorization_key']
+            self._credentials = None
+        if 'credentials' in data:
+            self._credentials = data['credentials']
 
     def _get_folder_id(self, path=''):
         now = time.time()
@@ -454,6 +456,8 @@ class Dropbox(UploadService):
         return self.AUTH_URL + '?' + urllib.urlencode(query)
 
     def test_access(self):
+        self._credentials = None # invalidate credentials
+
         body = {
             'path': self._clean_location(),
             'recursive': False,
@@ -502,10 +506,11 @@ class Dropbox(UploadService):
     def load(self, data):
         if 'location' in data:
             self._location = data['location']
-        if 'credentials' in data:
-            self._credentials = data['credentials']
         if 'authorization_key' in data:
             self._authorization_key = data['authorization_key']
+            self._credentials = None
+        if 'credentials' in data:
+            self._credentials = data['credentials']
     
     def _clean_location(self):
         location = self._location
@@ -604,8 +609,10 @@ def get(camera_id, service_name):
     
     if _services is None:
         _services = _load()
+        
+    camera_id = str(camera_id)
 
-    service = _services.get(str(camera_id), {}).get(service_name)
+    service = _services.get(camera_id, {}).get(service_name)
     if service is None:
         cls = UploadService.get_service_classes().get(service_name)
         if cls:
@@ -673,7 +680,7 @@ def _save(services):
     data = {}
     for camera_id, camera_services in services.iteritems():
         for name, service in camera_services.iteritems():
-            data.setdefault(camera_id, {})[name] = service.dump()
+            data.setdefault(str(camera_id), {})[name] = service.dump()
 
     try:
         json.dump(data, file, sort_keys=True, indent=4)
@@ -685,6 +692,12 @@ def _save(services):
         file.close()
 
 
+def invalidate():
+    global _services
+    
+    _services = None
+
+
 def upload_media_file(camera_id, target_dir, service_name, filename):
     service = get(camera_id, service_name)
     if not service:
@@ -694,4 +707,4 @@ def upload_media_file(camera_id, target_dir, service_name, filename):
         service.upload_file(target_dir, filename)
 
     except Exception as e:
-        logging.error('failed to upload file "%s" with service %s: %s' % (filename, service, e))
+        logging.error('failed to upload file "%s" with service %s: %s' % (filename, service, e), exc_info=True)