blueprints: add icons blueprint

- Pipfile: add pillow
This commit is contained in:
Luna Mendes 2018-11-13 17:33:28 -03:00
parent e694348274
commit e54bcc312a
6 changed files with 89 additions and 6 deletions

View File

@ -12,6 +12,7 @@ Earl-ETF = "==2.1.2"
logbook = "==1.4.0" logbook = "==1.4.0"
Cerberus = "==1.2" Cerberus = "==1.2"
quart = {editable = true, ref = "e23714d5", git = "https://gitlab.com/pgjones/quart"} quart = {editable = true, ref = "e23714d5", git = "https://gitlab.com/pgjones/quart"}
pillow = "*"
[dev-packages] [dev-packages]
pytest = "==3.10.1" pytest = "==3.10.1"

38
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "58f2b37ff181f4deadceb9cee85bff244bb9702b24bbca31c9f5471b7c959663" "sha256": "277049fb25e5f182fc611cc27c1d07792cea31f137375bd48f654ddb94d2eb62"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -282,6 +282,42 @@
], ],
"version": "==4.4.2" "version": "==4.4.2"
}, },
"pillow": {
"hashes": [
"sha256:00203f406818c3f45d47bb8fe7e67d3feddb8dcbbd45a289a1de7dd789226360",
"sha256:0616f800f348664e694dddb0b0c88d26761dd5e9f34e1ed7b7a7d2da14b40cb7",
"sha256:1f7908aab90c92ad85af9d2fec5fc79456a89b3adcc26314d2cde0e238bd789e",
"sha256:2ea3517cd5779843de8a759c2349a3cd8d3893e03ab47053b66d5ec6f8bc4f93",
"sha256:48a9f0538c91fc136b3a576bee0e7cd174773dc9920b310c21dcb5519722e82c",
"sha256:5280ebc42641a1283b7b1f2c20e5b936692198b9dd9995527c18b794850be1a8",
"sha256:5e34e4b5764af65551647f5cc67cf5198c1d05621781d5173b342e5e55bf023b",
"sha256:63b120421ab85cad909792583f83b6ca3584610c2fe70751e23f606a3c2e87f0",
"sha256:696b5e0109fe368d0057f484e2e91717b49a03f1e310f857f133a4acec9f91dd",
"sha256:870ed021a42b1b02b5fe4a739ea735f671a84128c0a666c705db2cb9abd528eb",
"sha256:916da1c19e4012d06a372127d7140dae894806fad67ef44330e5600d77833581",
"sha256:9303a289fa0811e1c6abd9ddebfc770556d7c3311cb2b32eff72164ddc49bc64",
"sha256:9577888ecc0ad7d06c3746afaba339c94d62b59da16f7a5d1cff9e491f23dace",
"sha256:987e1c94a33c93d9b209315bfda9faa54b8edfce6438a1e93ae866ba20de5956",
"sha256:99a3bbdbb844f4fb5d6dd59fac836a40749781c1fa63c563bc216c27aef63f60",
"sha256:99db8dc3097ceafbcff9cb2bff384b974795edeb11d167d391a02c7bfeeb6e16",
"sha256:a5a96cf49eb580756a44ecf12949e52f211e20bffbf5a95760ac14b1e499cd37",
"sha256:aa6ca3eb56704cdc0d876fc6047ffd5ee960caad52452fbee0f99908a141a0ae",
"sha256:aade5e66795c94e4a2b2624affeea8979648d1b0ae3fcee17e74e2c647fc4a8a",
"sha256:b78905860336c1d292409e3df6ad39cc1f1c7f0964e66844bbc2ebfca434d073",
"sha256:b92f521cdc4e4a3041cc343625b699f20b0b5f976793fb45681aac1efda565f8",
"sha256:bfde84bbd6ae5f782206d454b67b7ee8f7f818c29b99fd02bf022fd33bab14cb",
"sha256:c2b62d3df80e694c0e4a0ed47754c9480521e25642251b3ab1dff050a4e60409",
"sha256:c5e2be6c263b64f6f7656e23e18a4a9980cffc671442795682e8c4e4f815dd9f",
"sha256:c99aa3c63104e0818ec566f8ff3942fb7c7a8f35f9912cb63fd8e12318b214b2",
"sha256:dae06620d3978da346375ebf88b9e2dd7d151335ba668c995aea9ed07af7add4",
"sha256:db5499d0710823fa4fb88206050d46544e8f0e0136a9a5f5570b026584c8fd74",
"sha256:f36baafd82119c4a114b9518202f2a983819101dcc14b26e43fc12cbefdce00e",
"sha256:f52b79c8796d81391ab295b04e520bda6feed54d54931708872e8f9ae9db0ea1",
"sha256:ff8cff01582fa1a7e533cb97f628531c4014af4b5f38e33cdcfe5eec29b6d888"
],
"index": "pypi",
"version": "==5.3.0"
},
"pycparser": { "pycparser": {
"hashes": [ "hashes": [
"sha256:a988718abfad80b6b157acce7bf130a30876d27603738ac39f140993246b25b3" "sha256:a988718abfad80b6b157acce7bf130a30876d27603738ac39f140993246b25b3"

View File

@ -9,7 +9,8 @@ from .voice import bp as voice
from .invites import bp as invites from .invites import bp as invites
from .relationships import bp as relationships from .relationships import bp as relationships
from .dms import bp as dms from .dms import bp as dms
from .icons import bp as icons
__all__ = ['gateway', 'auth', 'users', 'guilds', 'channels', __all__ = ['gateway', 'auth', 'users', 'guilds', 'channels',
'webhooks', 'science', 'voice', 'invites', 'relationships', 'webhooks', 'science', 'voice', 'invites', 'relationships',
'dms'] 'dms', 'icons']

View File

@ -0,0 +1,35 @@
from quart import Blueprint, current_app as app, send_file
bp = Blueprint('images', __name__)
@bp.route('/emojis/<int:emoji_id>.<ext>', methods=['GET'])
async def get_raw_emoji(emoji_id: int, ext: str):
# emoji = app.icons.get_emoji(emoji_id, ext=ext)
# just a test file for now
return await send_file('./LICENSE')
@bp.route('/icons/<int:guild_id>/<icon_hash>.<ext>', methods=['GET'])
async def get_guild_icon(guild_id: int, icon_hash: str, ext: str):
pass
@bp.route('/splashes/<int:guild_id>/<icon_hash>.<ext>', methods=['GET'])
async def get_guild_splash(guild_id: int, splash_hash: str, ext: str):
pass
@bp.route('/embed/avatars/<int:discrim>.png')
async def get_default_user_avatar(discrim: int):
pass
@bp.route('/avatars/<int:user_id>/<avatar_hash>.<ext>')
async def get_user_avatar(user_id, avatar_hash, ext):
pass
# @bp.route('/app-icons/<int:application_id>/<icon_hash>.<ext>')
async def get_app_icon(application_id, icon_hash, ext):
pass

6
litecord/images.py Normal file
View File

@ -0,0 +1,6 @@
MIMES = {
}
class IconManager:
"""Main icon manager."""

12
run.py
View File

@ -14,7 +14,7 @@ import config
from litecord.blueprints import ( from litecord.blueprints import (
gateway, auth, users, guilds, channels, webhooks, science, gateway, auth, users, guilds, channels, webhooks, science,
voice, invites, relationships, dms voice, invites, relationships, dms, icons
) )
# those blueprints are separated from the "main" ones # those blueprints are separated from the "main" ones
@ -85,12 +85,14 @@ def set_blueprints(app_):
science: None, science: None,
voice: '/voice', voice: '/voice',
invites: None, invites: None,
dms: '/users' dms: '/users',
icons: -1,
} }
for bp, suffix in bps.items(): for bp, suffix in bps.items():
suffix = suffix or '' url_prefix = f'/api/v6/{suffix or ""}' if suffix != -1 else ''
app_.register_blueprint(bp, url_prefix=f'/api/v6{suffix}') app_.register_blueprint(bp, url_prefix=url_prefix)
app = make_app() app = make_app()
@ -99,6 +101,8 @@ set_blueprints(app)
@app.before_request @app.before_request
async def app_before_request(): async def app_before_request():
"""Functions to call before the request actually
takes place."""
await ratelimit_handler() await ratelimit_handler()