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
                     new_text = '<a href="https://{1}.tumblr.com/">{0}</a>'.format(
221
                     new_text = '<a href="https://{1}.tumblr.com/">{0}</a>'.format(
222
                         username, username.lower()
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
         description = description[0:start] + new_text + description[end:]
229
         description = description[0:start] + new_text + description[end:]
226
 
230
 

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

1
 from typing import List
1
 from typing import List
2
+import json
2
 
3
 
3
 import requests
4
 import requests
4
 from flask import Blueprint, Response, g, jsonify, request, session
5
 from flask import Blueprint, Response, g, jsonify, request, session
7
 from cache import cache
8
 from cache import cache
8
 from constant import HEADERS, Sites
9
 from constant import HEADERS, Sites
9
 from description import parse_description
10
 from description import parse_description
10
-from models import Account, SavedTemplate, db
11
+from models import Account, SavedTemplate, SavedSubmission, User, db
11
 from simplecrypt import decrypt
12
 from simplecrypt import decrypt
12
 from sites.deviantart import DeviantArt
13
 from sites.deviantart import DeviantArt
13
 from sites.known import known_list
14
 from sites.known import known_list
27
 
28
 
28
 
29
 
29
 @app.route('/whoami')
30
 @app.route('/whoami')
30
-@login_required
31
 def whoami():
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
 @app.route('/accounts')
41
 @app.route('/accounts')
49
     return jsonify({'accounts': accts})
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
 @app.route('/description', methods=['POST'])
80
 @app.route('/description', methods=['POST'])
53
 @login_required
81
 @login_required
54
 def description():
82
 def description():

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

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

Loading…
Cancel
Save