aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/submit
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/submit')
-rw-r--r--mediagoblin/submit/lib.py31
-rwxr-xr-xmediagoblin/submit/task.py38
2 files changed, 69 insertions, 0 deletions
diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py
index 93ae7a1f..327ebbd8 100644
--- a/mediagoblin/submit/lib.py
+++ b/mediagoblin/submit/lib.py
@@ -22,6 +22,7 @@ from werkzeug.utils import secure_filename
from werkzeug.datastructures import FileStorage
from mediagoblin import mg_globals
+from mediagoblin.tools.response import json_response
from mediagoblin.tools.text import convert_to_tag_list_of_dicts
from mediagoblin.db.models import MediaEntry, ProcessingMetaData
from mediagoblin.processing import mark_entry_failed
@@ -259,3 +260,33 @@ def run_process_media(entry, feed_url=None,
mark_entry_failed(entry.id, exc)
# re-raise the exception
raise
+
+
+def api_upload_request(request, file_data, entry):
+ """ This handles a image upload request """
+ # Use the same kind of method from mediagoblin/submit/views:submit_start
+ entry.title = file_data.filename
+ entry.generate_slug()
+
+ queue_file = prepare_queue_task(request.app, entry, file_data.filename)
+ with queue_file:
+ queue_file.write(request.data)
+
+ entry.save()
+ return json_response(entry.serialize(request))
+
+def api_add_to_feed(request, entry):
+ """ Add media to Feed """
+ if entry.title:
+ # Shame we have to do this here but we didn't have the data in
+ # api_upload_request as no filename is usually specified.
+ entry.slug = None
+ entry.generate_slug()
+
+ feed_url = request.urlgen(
+ 'mediagoblin.user_pages.atom_feed',
+ qualified=True, user=request.user.username)
+
+ run_process_media(entry, feed_url)
+ add_comment_subscription(request.user, entry)
+ return json_response(entry.serialize(request)) \ No newline at end of file
diff --git a/mediagoblin/submit/task.py b/mediagoblin/submit/task.py
new file mode 100755
index 00000000..4ebde502
--- /dev/null
+++ b/mediagoblin/submit/task.py
@@ -0,0 +1,38 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import celery
+import datetime
+import pytz
+
+from mediagoblin.db.models import MediaEntry
+
+@celery.task()
+def collect_garbage():
+ """
+ Garbage collection to clean up media
+
+ This will look for all critera on models to clean
+ up. This is primerally written to clean up media that's
+ entered a erroneous state.
+ """
+ cuttoff = datetime.datetime.now(pytz.UTC) - datetime.timedelta(days=1)
+
+ garbage = MediaEntry.query.filter(MediaEntry.created < cuttoff)
+ garbage = garbage.filter(MediaEntry.state == "unprocessed")
+
+ for entry in garbage.all():
+ entry.delete()