Browse Source

Fix DeviantArt tags.

Syfaro 1 month ago
parent
commit
3f47cf63f9
3 changed files with 40 additions and 6 deletions
  1. 4
    0
      src/description.py
  2. 31
    3
      src/routes/api.py
  3. 5
    3
      src/sites/deviantart.py

+ 4
- 0
src/description.py View File

@@ -221,6 +221,10 @@ def parse_description(description, uploading_to) -> str:
221 221
                     new_text = '<a href="https://{1}.tumblr.com/">{0}</a>'.format(
222 222
                         username, username.lower()
223 223
                     )
224
+                elif linking_to == 100:
225
+                    new_text = '<a href="https://twitter.com/{0}">{0}</a>'.format(username)
226
+                elif linking_to == 101:
227
+                    new_text = '<a href="{0}">{1}</a>'.format(masto_link, username)
224 228
 
225 229
         description = description[0:start] + new_text + description[end:]
226 230
 

+ 31
- 3
src/routes/api.py View File

@@ -1,4 +1,5 @@
1 1
 from typing import List
2
+import json
2 3
 
3 4
 import requests
4 5
 from flask import Blueprint, Response, g, jsonify, request, session
@@ -7,7 +8,7 @@ import simplecrypt
7 8
 from cache import cache
8 9
 from constant import HEADERS, Sites
9 10
 from description import parse_description
10
-from models import Account, SavedTemplate, db
11
+from models import Account, SavedTemplate, SavedSubmission, User, db
11 12
 from simplecrypt import decrypt
12 13
 from sites.deviantart import DeviantArt
13 14
 from sites.known import known_list
@@ -27,9 +28,14 @@ def sites():
27 28
 
28 29
 
29 30
 @app.route('/whoami')
30
-@login_required
31 31
 def whoami():
32
-    return jsonify({'id': g.user.id, 'username': g.user.username})
32
+    session_id = session.get('id')
33
+    if session_id:
34
+        user: User = User.query.get(session['id'])
35
+        if user:
36
+            return jsonify({'id': user.id, 'username': user.username})
37
+
38
+    return jsonify({'id': None, 'username': None})
33 39
 
34 40
 
35 41
 @app.route('/accounts')
@@ -49,6 +55,28 @@ def accounts():
49 55
     return jsonify({'accounts': accts})
50 56
 
51 57
 
58
+@app.route('/submissions')
59
+@login_required
60
+def submissions():
61
+    subs = SavedSubmission.query.filter_by(user_id=g.user.id).all()
62
+
63
+    subs = list(map(lambda sub: {
64
+        'id': sub.id,
65
+        'title': sub.title,
66
+        'description': sub.description,
67
+        'tags': sub.tags,
68
+        'original_filename': sub.original_filename,
69
+        'image_filename': sub.image_filename,
70
+        'image_mimetype': sub.image_mimetype,
71
+        'account_ids': sub.account_ids,
72
+        'site_data': json.loads(sub.site_data),
73
+        'group_id': sub.group_id,
74
+        'master': sub.master,
75
+    }, subs))
76
+
77
+    return jsonify(subs)
78
+
79
+
52 80
 @app.route('/description', methods=['POST'])
53 81
 @login_required
54 82
 def description():

+ 5
- 3
src/sites/deviantart.py View File

@@ -141,8 +141,6 @@ class DeviantArt(Site):
141 141
     def submit_artwork(self, submission: Submission, extra: Any = None) -> str:
142 142
         da = self.get_da()
143 143
 
144
-
145
-
146 144
         r = da.refresh_token(self.credentials)
147 145
         self.account.update_credentials(r['refresh_token'])
148 146
         db.session.commit()
@@ -150,6 +148,10 @@ class DeviantArt(Site):
150 148
         if r['status'] != 'success':
151 149
             raise BadCredentials()
152 150
 
151
+        tags = {}
152
+        for idx, tag in enumerate(submission.tags):
153
+            tags['tags[{idx}]'.format(idx=idx)] = tag
154
+
153 155
         sub = requests.post(
154 156
             'https://www.deviantart.com/api/v1/oauth2/stash/submit',
155 157
             headers=HEADERS,
@@ -157,7 +159,7 @@ class DeviantArt(Site):
157 159
                 'access_token': r['access_token'],
158 160
                 'title': submission.title,
159 161
                 'artist_comments': submission.description_for_site(self.SITE),
160
-                'tags': self.tag_str(submission.tags),
162
+                **tags,
161 163
             },
162 164
             files={'image': submission.get_image()},
163 165
         ).json()

Loading…
Cancel
Save