-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.py
70 lines (50 loc) · 2.41 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/python
import random
import sys
import uuid
from base36 import base36encode
from string import Template
# URL for web-based gallery administration
ADMIN_URL = '/'
# Demo mode prevents any changes but simulates correct responses.
DEMO_MODE = False
# URL prefix for all gallery albums
ALBUM_ROOT_URL = '/albums'
# Template to generate an album API URL
ALBUM_URL_TEMPLATE_STRING = ALBUM_ROOT_URL + '/${album_id}'
ALBUM_URL_TEMPLATE = Template(ALBUM_URL_TEMPLATE_STRING)
# Generator and matching regex for album IDs
ALBUM_ID_GENERATOR = lambda: str(uuid.uuid4())
ALBUM_ID_REGEX = r'([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})'
# URL regex for all albums
ALBUM_URL_REGEX = ALBUM_URL_TEMPLATE.substitute({'album_id': ALBUM_ID_REGEX})
# URL component for an album image root
IMAGE_RELATIVE_URL = 'images'
# Template to generate an API URL for an album image root
IMAGE_ROOT_URL_TEMPLATE_STRING = ALBUM_URL_TEMPLATE_STRING + '/' + IMAGE_RELATIVE_URL
IMAGE_ROOT_URL_TEMPLATE = Template(IMAGE_ROOT_URL_TEMPLATE_STRING)
# URL regex for all album image roots
IMAGE_ROOT_URL_REGEX = IMAGE_ROOT_URL_TEMPLATE.substitute({'album_id': ALBUM_ID_REGEX})
# Template to generate an image API URL
IMAGE_URL_TEMPLATE_STRING = IMAGE_ROOT_URL_TEMPLATE_STRING + '/${image_id}'
IMAGE_URL_TEMPLATE = Template(IMAGE_URL_TEMPLATE_STRING)
# Generator and matching regex for image IDs
IMAGE_ID_GENERATOR = lambda: str(uuid.uuid4())
IMAGE_ID_REGEX = r'([\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12})'
# Regex for valid file extensions
FILE_EXT_REGEX = r'(\.(?:BMP|bmp|JPG|jpg|JPEG|jpeg|PNG|png|gif|GIF|tif|TIF|tiff|TIFF))?'
# URL regex for all images
IMAGE_URL_REGEX = IMAGE_URL_TEMPLATE.substitute({'album_id': ALBUM_ID_REGEX,
'image_id': IMAGE_ID_REGEX + FILE_EXT_REGEX})
# URL prefix for all shareable items
SHARE_ROOT_URL = '/share'
# Function to generate a random index for all shareable items
SHARE_INDEX_GENERATOR = lambda: random.randint(0, sys.maxint)
# Template to generate a shareable URL
SHARE_URL_TEMPLATE_STRING = SHARE_ROOT_URL + '/${hash}'
SHARE_URL_TEMPLATE = Template(SHARE_URL_TEMPLATE_STRING)
# Generator and matching regex for shareable URL hashes
SHARE_HASH_GENERATOR = lambda index: base36encode(index)
SHARE_HASH_REGEX = r'([0-9a-z]{1,' + str(len(str(sys.maxint))) + '})'
# URL regex for all shareable items
SHARE_URL_REGEX = SHARE_URL_TEMPLATE.substitute({'hash': SHARE_HASH_REGEX + FILE_EXT_REGEX})