Added create2 endpoint
This commit is contained in:
parent
7fb5c47e4d
commit
af299a53c7
2 changed files with 42 additions and 3 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
* Schema changes: moved `full_name` field from table `userprofile` to table `user` for search improvement reasons.
|
* Schema changes: moved `full_name` field from table `userprofile` to table `user` for search improvement reasons.
|
||||||
* Adding `messages_count`, `followers_count` and `following_count` to `profile_info` API endpoint (what I've done to 0.7.1 too).
|
* Adding `messages_count`, `followers_count` and `following_count` to `profile_info` API endpoint (what I've done to 0.7.1 too).
|
||||||
|
* Adding `create2` API endpoint that accepts media, due to an issue with the `create` endpoint that would make it incompatible.
|
||||||
* Adding media URLs to messages in API.
|
* Adding media URLs to messages in API.
|
||||||
* Added `relationships_follow`, `relationships_unfollow`, `username_availability` and `edit_profile` endpoints to API.
|
* Added `relationships_follow`, `relationships_unfollow`, `username_availability` and `edit_profile` endpoints to API.
|
||||||
* Added `url` utility to model `Upload`.
|
* Added `url` utility to model `Upload`.
|
||||||
|
|
|
||||||
44
app/api.py
44
app/api.py
|
|
@ -1,9 +1,9 @@
|
||||||
from flask import Blueprint, jsonify, request
|
from flask import Blueprint, jsonify, request
|
||||||
import sys, datetime, re
|
import sys, os, datetime, re
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from peewee import IntegrityError
|
from peewee import IntegrityError
|
||||||
from .models import User, Message, Relationship, database, \
|
from .models import User, Message, Upload, Relationship, database, \
|
||||||
MSGPRV_PUBLIC, MSGPRV_UNLISTED, MSGPRV_FRIENDS, MSGPRV_ONLYME
|
MSGPRV_PUBLIC, MSGPRV_UNLISTED, MSGPRV_FRIENDS, MSGPRV_ONLYME, UPLOAD_DIRECTORY
|
||||||
from .utils import check_access_token, Visibility, push_notification, unpush_notification
|
from .utils import check_access_token, Visibility, push_notification, unpush_notification
|
||||||
|
|
||||||
bp = Blueprint('api', __name__, url_prefix='/api/V1')
|
bp = Blueprint('api', __name__, url_prefix='/api/V1')
|
||||||
|
|
@ -103,6 +103,44 @@ def create(self):
|
||||||
push_notification('mention', mention_user, user=user.id)
|
push_notification('mention', mention_user, user=user.id)
|
||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
return {}
|
||||||
|
|
||||||
|
@bp.route('/create2', methods=['POST'])
|
||||||
|
@validate_access
|
||||||
|
def create2(self):
|
||||||
|
text = request.form['text']
|
||||||
|
privacy = int(request.form.get('privacy', 0))
|
||||||
|
message = Message.create(
|
||||||
|
user=self,
|
||||||
|
text=text,
|
||||||
|
pub_date=datetime.datetime.now(),
|
||||||
|
privacy=privacy)
|
||||||
|
file = request.files.get('file')
|
||||||
|
if file:
|
||||||
|
print('Uploading', file.filename)
|
||||||
|
ext = file.filename.split('.')[-1]
|
||||||
|
upload = Upload.create(
|
||||||
|
type=ext,
|
||||||
|
message=message
|
||||||
|
)
|
||||||
|
file.save(os.path.join(UPLOAD_DIRECTORY, str(upload.id) + '.' + ext))
|
||||||
|
# create mentions
|
||||||
|
mention_usernames = set()
|
||||||
|
for mo in re.finditer(r'\+([A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*)', text):
|
||||||
|
mention_usernames.add(mo.group(1))
|
||||||
|
# to avoid self mention
|
||||||
|
mention_usernames.difference_update({self.username})
|
||||||
|
for u in mention_usernames:
|
||||||
|
try:
|
||||||
|
mention_user = User.get(User.username == u)
|
||||||
|
if privacy in (MSGPRV_PUBLIC, MSGPRV_UNLISTED) or \
|
||||||
|
(privacy == MSGPRV_FRIENDS and
|
||||||
|
mention_user.is_following(self) and
|
||||||
|
self.is_following(mention_user)):
|
||||||
|
push_notification('mention', mention_user, user=user.id)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
pass
|
||||||
|
return {}
|
||||||
|
|
||||||
def get_relationship_info(self, other):
|
def get_relationship_info(self, other):
|
||||||
if self == other:
|
if self == other:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue