thumbor-libs-blackhand 0.4.0__tar.gz → 0.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- thumbor_libs_blackhand-0.5.1/LICENSE +21 -0
- {thumbor_libs_blackhand-0.4.0 → thumbor_libs_blackhand-0.5.1}/PKG-INFO +18 -6
- thumbor_libs_blackhand-0.5.1/README.md +221 -0
- thumbor_libs_blackhand-0.5.1/setup.cfg +4 -0
- {thumbor_libs_blackhand-0.4.0 → thumbor_libs_blackhand-0.5.1}/setup.py +6 -5
- thumbor_libs_blackhand-0.5.1/thumbor_libs_blackhand/result_storages/mongodb_result_storage_v5.py +178 -0
- thumbor_libs_blackhand-0.5.1/thumbor_libs_blackhand.egg-info/PKG-INFO +32 -0
- thumbor_libs_blackhand-0.5.1/thumbor_libs_blackhand.egg-info/SOURCES.txt +23 -0
- thumbor_libs_blackhand-0.5.1/thumbor_libs_blackhand.egg-info/dependency_links.txt +1 -0
- thumbor_libs_blackhand-0.5.1/thumbor_libs_blackhand.egg-info/requires.txt +2 -0
- thumbor_libs_blackhand-0.5.1/thumbor_libs_blackhand.egg-info/top_level.txt +1 -0
- {thumbor_libs_blackhand-0.4.0 → thumbor_libs_blackhand-0.5.1}/thumbor_libs_blackhand/loaders/__init__.py +0 -0
- {thumbor_libs_blackhand-0.4.0 → thumbor_libs_blackhand-0.5.1}/thumbor_libs_blackhand/loaders/mongodb_loader.py +0 -0
- {thumbor_libs_blackhand-0.4.0 → thumbor_libs_blackhand-0.5.1}/thumbor_libs_blackhand/loaders/spec_http_or_specb_loader.py +0 -0
- {thumbor_libs_blackhand-0.4.0 → thumbor_libs_blackhand-0.5.1}/thumbor_libs_blackhand/loaders/specb_file_fallback_file_loader.py +0 -0
- {thumbor_libs_blackhand-0.4.0 → thumbor_libs_blackhand-0.5.1}/thumbor_libs_blackhand/metrics/__init__.py +0 -0
- {thumbor_libs_blackhand-0.4.0 → thumbor_libs_blackhand-0.5.1}/thumbor_libs_blackhand/mongodb/pool_result_storage.py +0 -0
- {thumbor_libs_blackhand-0.4.0 → thumbor_libs_blackhand-0.5.1}/thumbor_libs_blackhand/result_storages/__init__.py +0 -0
- {thumbor_libs_blackhand-0.4.0 → thumbor_libs_blackhand-0.5.1}/thumbor_libs_blackhand/result_storages/hybrid_result_storage.py +0 -0
- {thumbor_libs_blackhand-0.4.0 → thumbor_libs_blackhand-0.5.1}/thumbor_libs_blackhand/result_storages/mongodb_result_storage_v3.py +0 -0
- {thumbor_libs_blackhand-0.4.0 → thumbor_libs_blackhand-0.5.1}/thumbor_libs_blackhand/result_storages/mongodb_result_storage_v4.py +0 -0
- {thumbor_libs_blackhand-0.4.0 → thumbor_libs_blackhand-0.5.1}/thumbor_libs_blackhand/storages/__init__.py +0 -0
- {thumbor_libs_blackhand-0.4.0 → thumbor_libs_blackhand-0.5.1}/thumbor_libs_blackhand/storages/mongodb_webp_storage.py +0 -0
- {thumbor_libs_blackhand-0.4.0 → thumbor_libs_blackhand-0.5.1}/thumbor_libs_blackhand/url_signers/__init__.py +0 -0
- {thumbor_libs_blackhand-0.4.0 → thumbor_libs_blackhand-0.5.1}/thumbor_libs_blackhand/url_signers/base64_hmac_sha1_trim.py +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Blackhand.org
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,20 +1,32 @@
|
|
|
1
|
-
Metadata-Version:
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: thumbor_libs_blackhand
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: libs thumbor
|
|
5
5
|
Home-page: https://github.com/Bkhand/thumbor_libs_blackhand
|
|
6
6
|
Author: Bertrand Thill
|
|
7
7
|
Author-email: github@blackhand.org
|
|
8
8
|
License: GNU
|
|
9
|
-
Description: This module enable mongodb support and fallback for thumbor.
|
|
10
|
-
|
|
11
9
|
Keywords: thumbor,fallback,images,nfs,mongodb
|
|
12
|
-
Platform: UNKNOWN
|
|
13
10
|
Classifier: Development Status :: 4 - Beta
|
|
14
11
|
Classifier: Intended Audience :: Developers
|
|
15
12
|
Classifier: License :: OSI Approved :: MIT License
|
|
16
13
|
Classifier: Natural Language :: French
|
|
17
14
|
Classifier: Operating System :: POSIX :: Linux
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
16
|
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
20
17
|
Classifier: Topic :: Multimedia :: Graphics :: Presentation
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: thumbor>=7.7.0
|
|
20
|
+
Requires-Dist: pymongo>=4.2.0
|
|
21
|
+
Dynamic: author
|
|
22
|
+
Dynamic: author-email
|
|
23
|
+
Dynamic: classifier
|
|
24
|
+
Dynamic: description
|
|
25
|
+
Dynamic: home-page
|
|
26
|
+
Dynamic: keywords
|
|
27
|
+
Dynamic: license
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
Dynamic: requires-dist
|
|
30
|
+
Dynamic: summary
|
|
31
|
+
|
|
32
|
+
This module enable mongodb support and fallback for thumbor.
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# thumbor_libs_blackhand
|
|
2
|
+
Libs for thumbor 7+
|
|
3
|
+
|
|
4
|
+
## Table of Contents
|
|
5
|
+
1. [General](#General)
|
|
6
|
+
2. [Loaders](#Loaders)
|
|
7
|
+
3. [Storages](#Storages)
|
|
8
|
+
4. [Result_storages](#Result_storages)
|
|
9
|
+
5. [Url_signers](#Url_signers)
|
|
10
|
+
6. [FAQs](#faqs)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# General
|
|
15
|
+
|
|
16
|
+
Collection de modules pour Thumbor 7+ Python3
|
|
17
|
+
|
|
18
|
+
Ces libs ne sont pas destin�es a tourner en production (absence du stack de test)
|
|
19
|
+
|
|
20
|
+
Test seulement.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
Environnement:
|
|
24
|
+
```
|
|
25
|
+
Thumbor 7.7.x
|
|
26
|
+
Python 3.12
|
|
27
|
+
MongoDB 7/8
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
# Loaders
|
|
31
|
+
|
|
32
|
+
1. [spec_http_fallback_file_loader] (#spec_http_fallback_file_loader)
|
|
33
|
+
2. [specb_http_or_specb_loader] (#specb_http_or_specb_loader)
|
|
34
|
+
2. [mongodb_loader] (#mongodb_loader)
|
|
35
|
+
|
|
36
|
+
## spec_http_fallback_file_loader
|
|
37
|
+
|
|
38
|
+
Description: Loader de type file, avec un fallback sur un autre filesystem.
|
|
39
|
+
|
|
40
|
+
Implementation:
|
|
41
|
+
```
|
|
42
|
+
LOADER = thumbor_libs_blackhand.loaders.spec_http_fallback_file_loader
|
|
43
|
+
PIC_LOADER_ROOT_PATH = #root path for file
|
|
44
|
+
PIC_LOADER_FALLBACK_PATH = #fallback path for file
|
|
45
|
+
PIC_LOADER_MAX_SIZE = #max size in bytes default 16777216
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## specb_http_or_specb_loader
|
|
49
|
+
|
|
50
|
+
Description: Loader de type spec_http_fallback_file_loader, avec un fallback sur du http/s http_loader.
|
|
51
|
+
|
|
52
|
+
Implementation:
|
|
53
|
+
```
|
|
54
|
+
LOADER = thumbor_libs_blackhand.loaders.specb_http_or_specb_loader
|
|
55
|
+
PIC_LOADER_ROOT_PATH = #root path for file
|
|
56
|
+
PIC_LOADER_FALLBACK_PATH = #fallback path for file
|
|
57
|
+
PIC_LOADER_MAX_SIZE = #max size in bytes default 16777216
|
|
58
|
+
|
|
59
|
+
#Ajouter les options additionnelles du LOADER http_loader standard
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## mongodb_loader
|
|
63
|
+
|
|
64
|
+
Description: Loader pour MongoDB/Gridfs.
|
|
65
|
+
|
|
66
|
+
Implementation:
|
|
67
|
+
```
|
|
68
|
+
LOADER = 'thumbor_libs_blackhand.loaders.mongodb_loader'
|
|
69
|
+
MONGO_ORIGIN_DB = 'thumbor' # MongoDB loader database name
|
|
70
|
+
MONGO_ORIGIN_COLLECTION = '<nom de la collection>' #host
|
|
71
|
+
MONGO_ORIGIN_URI = 'url de connection vers mongoDB mongodb://'
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Url type:
|
|
75
|
+
```
|
|
76
|
+
https://thumbor-server.domain/[secret|unsafe]/[params]/XXXXXXXXXXXXXXXXXXXXXX[/.../..../.xxx <= all is facultative after id ]
|
|
77
|
+
where `XXXXXXXXXXXXXXXXXXXXXX` is a GridFS `file_id`
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Note: avec utilisation de Varnish quelques modifs sont r�aliser
|
|
81
|
+
```
|
|
82
|
+
##### Configuration example for varnish (recv) with AUTO_WEBP ####
|
|
83
|
+
if (req.http.Accept ~ "image/webp") {
|
|
84
|
+
set req.http.Accept = "image/webp";
|
|
85
|
+
} else {
|
|
86
|
+
# not present, and we don't care about the rest
|
|
87
|
+
unset req.http.Accept;
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
# storages
|
|
92
|
+
|
|
93
|
+
## mongodb_webp_storage (LEGACY)
|
|
94
|
+
|
|
95
|
+
Description: Stockage des images pour MongoDB/GridFS compatible avec la fonction auto_webp.
|
|
96
|
+
|
|
97
|
+
Implementation:
|
|
98
|
+
```
|
|
99
|
+
STORAGE = 'thumbor_libs_blackhand.storages.mongo_webp_storage'
|
|
100
|
+
MONGO_STORAGE_DB = 'thumbor' # MongoDB storage server database name
|
|
101
|
+
MONGO_STORAGE_DB = 'thumbor' # MongoDB storage server database name
|
|
102
|
+
MONGO_STORAGE_COLLECTION = 'images' # MongoDB storage image collection
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
# Result_storages
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
## mongodb_result_storage_V3 V4
|
|
110
|
+
|
|
111
|
+
Description: Mise en cache des images pour MongoDB compatible avec la fonction auto_webp. Attention l'expiration doit �tre ger�e via un index TTL Mongo.
|
|
112
|
+
|
|
113
|
+
Implementation:
|
|
114
|
+
```
|
|
115
|
+
RESULT_STORAGE = 'thumbor_libs_blackhand.result_storages.mongo_result_storage_v3/4'
|
|
116
|
+
MONGO_RESULT_STORAGE_SERVER_AUTH = "auth base in mongodb"
|
|
117
|
+
MONGO_RESULT_STORAGE_SERVER_COLLECTION = "collection to store image & metadata"
|
|
118
|
+
MONGO_RESULT_STORAGE_SERVER_DB = "base mongodb"
|
|
119
|
+
MONGO_RESULT_STORAGE_SERVER_HOST = "host1,host2 ..."
|
|
120
|
+
MONGO_RESULT_STORAGE_SERVER_PASSWORD = "password"
|
|
121
|
+
MONGO_RESULT_STORAGE_SERVER_PORT = "27017"
|
|
122
|
+
MONGO_RESULT_STORAGE_SERVER_READ_PREFERENCE = "secondaryPreferred"
|
|
123
|
+
MONGO_RESULT_STORAGE_SERVER_REPLICASET = "name of replicaset"
|
|
124
|
+
MONGO_RESULT_STORAGE_SERVER_USER = "user"
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
V4 seulement:
|
|
128
|
+
```
|
|
129
|
+
PRODUIT = ['','']
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
## hybrid_result_storage
|
|
134
|
+
|
|
135
|
+
Description: Mise en cache des images pour MongoDB (metadata) + disk (binaire) compatible avec la fonction auto_webp. Attention l'expiration doit �tre ger�e via un index TTL Mongo - hors disque TODO.
|
|
136
|
+
|
|
137
|
+
Implementation:
|
|
138
|
+
```
|
|
139
|
+
RESULT_STORAGE = 'thumbor_libs_blackhand.result_storages.mongo_result_storage'
|
|
140
|
+
MONGO_RESULT_STORAGE_SERVER_AUTH = "auth base in mongodb"
|
|
141
|
+
MONGO_RESULT_STORAGE_SERVER_COLLECTION = "collection to store image & metadata"
|
|
142
|
+
MONGO_RESULT_STORAGE_SERVER_DB = "base mongodb"
|
|
143
|
+
MONGO_RESULT_STORAGE_SERVER_HOSTS = "host1,host2 ..."
|
|
144
|
+
MONGO_RESULT_STORAGE_SERVER_PASSWORD = "password"
|
|
145
|
+
MONGO_RESULT_STORAGE_SERVER_PORT = "27017"
|
|
146
|
+
MONGO_RESULT_STORAGE_SERVER_READ_PREFERENCE = "secondaryPreferred"
|
|
147
|
+
MONGO_RESULT_STORAGE_SERVER_REPLICASET = "name of replicaset"
|
|
148
|
+
MONGO_RESULT_STORAGE_SERVER_USER = "user"
|
|
149
|
+
CACHE_PATH = "path du storage du cache"
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Options:
|
|
153
|
+
```
|
|
154
|
+
MONGO_STORE_METADATA = True
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
Note: avec utilisation de Varnish quelques modifs sont r�aliser
|
|
159
|
+
|
|
160
|
+
Exemple: https://www.fastly.com/blog/test-new-encodings-fastly-including-webp
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
sub vcl_recv {
|
|
164
|
+
# Normalize Accept, we're only interested in webp right now.
|
|
165
|
+
# And only normalize for URLs we care about.
|
|
166
|
+
if (req.http.Accept && req.url ~ "(\.jpe?g|\.png)($|\?)") {
|
|
167
|
+
# So we don't have to keep using the above regex multiple times.
|
|
168
|
+
set req.http.X-Is-An-Image-URL = "yay";
|
|
169
|
+
|
|
170
|
+
# Test Le wep n'est pas acceptable
|
|
171
|
+
if (req.http.Accept ~ "image/webp[^,];q=0(\.0?0?0?)?[^0-9]($|[,;])") {
|
|
172
|
+
unset req.http.Accept;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
# Le webp est acceptable
|
|
176
|
+
if (req.http.Accept ~ "image/webp") {
|
|
177
|
+
set req.http.Accept = "image/webp";
|
|
178
|
+
} else {
|
|
179
|
+
# Header non present
|
|
180
|
+
unset req.http.Accept;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
#FASTLY recv
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
sub vcl_miss {
|
|
187
|
+
# Si vous avez /foo/bar.jpeg, vous pouvez aussi avoir /foo/bar.webp
|
|
188
|
+
|
|
189
|
+
if (req.http.Accept ~ "image/webp" && req.http.X-Is-An-Image-URL) {
|
|
190
|
+
set bereq.url = regsuball(bereq.url, "(\.jpe?g|\.png)($|\?)", ".webp\2");
|
|
191
|
+
}
|
|
192
|
+
#FASTLY miss
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
sub vcl_fetch {
|
|
196
|
+
if (req.http.X-Is-An-Image-URL) {
|
|
197
|
+
if (!beresp.http.Vary ~ "(^|\s|,)Accept($|\s|,)") {
|
|
198
|
+
if (beresp.http.Vary) {
|
|
199
|
+
set beresp.http.Vary = beresp.http.Vary ", Accept";
|
|
200
|
+
} else {
|
|
201
|
+
set beresp.http.Vary = "Accept";
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
#FASTLY fetch
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
# Url_signers
|
|
210
|
+
|
|
211
|
+
## base64_hmac_sha1_trim
|
|
212
|
+
|
|
213
|
+
Description: Url signers basique avec fonction trim.
|
|
214
|
+
|
|
215
|
+
Implementation:
|
|
216
|
+
```
|
|
217
|
+
URL_SIGNER = 'thumbor_libs_blackhand.url_signers.base64_hmac_sha1_trim'
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
# Metrics
|
|
221
|
+
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
# Licensed under the MIT license:
|
|
4
4
|
# http://www.opensource.org/licenses/mit-license
|
|
5
5
|
|
|
6
|
+
from setuptools import setup, find_packages
|
|
6
7
|
|
|
7
|
-
from distutils.core import setup
|
|
8
|
+
#from distutils.core import setup
|
|
8
9
|
|
|
9
10
|
setup(
|
|
10
11
|
name = "thumbor_libs_blackhand",
|
|
11
|
-
version = "0.
|
|
12
|
+
version = "0.5.1",
|
|
12
13
|
description = "libs thumbor",
|
|
13
14
|
author = "Bertrand Thill",
|
|
14
15
|
author_email = "github@blackhand.org",
|
|
@@ -29,13 +30,13 @@ setup(
|
|
|
29
30
|
'License :: OSI Approved :: MIT License',
|
|
30
31
|
'Natural Language :: French',
|
|
31
32
|
'Operating System :: POSIX :: Linux',
|
|
32
|
-
'Programming Language :: Python :: 3.
|
|
33
|
+
'Programming Language :: Python :: 3.12',
|
|
33
34
|
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
|
|
34
35
|
'Topic :: Multimedia :: Graphics :: Presentation'
|
|
35
36
|
],
|
|
36
37
|
package_dir = {"thumbor_libs_blackhand": "thumbor_libs_blackhand"},
|
|
37
|
-
install_requires=['thumbor>=7.
|
|
38
|
+
install_requires=['thumbor>=7.7.0','pymongo>=4.2.0'],
|
|
38
39
|
long_description = """\
|
|
39
40
|
This module enable mongodb support and fallback for thumbor.
|
|
40
41
|
"""
|
|
41
|
-
)
|
|
42
|
+
)
|
thumbor_libs_blackhand-0.5.1/thumbor_libs_blackhand/result_storages/mongodb_result_storage_v5.py
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Blackhand library for Thumbor
|
|
3
|
+
# Licensed under the MIT license:
|
|
4
|
+
# http://www.opensource.org/licenses/mit-license
|
|
5
|
+
|
|
6
|
+
from urllib import parse #, request; error
|
|
7
|
+
from thumbor_libs_blackhand.mongodb.pool_result_storage import MongoConnector
|
|
8
|
+
from datetime import datetime, timedelta
|
|
9
|
+
from thumbor.result_storages import BaseStorage, ResultStorageResult
|
|
10
|
+
from thumbor.engines import BaseEngine
|
|
11
|
+
from thumbor.utils import logger
|
|
12
|
+
from bson.binary import Binary
|
|
13
|
+
import pytz
|
|
14
|
+
import re
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Storage(BaseStorage):
|
|
18
|
+
|
|
19
|
+
def __init__(self, context):
|
|
20
|
+
BaseStorage.__init__(self, context)
|
|
21
|
+
self.database, self.storage = self.__conn__()
|
|
22
|
+
super(Storage, self).__init__(context)
|
|
23
|
+
|
|
24
|
+
def __conn__(self):
|
|
25
|
+
try:
|
|
26
|
+
uri = self.context.config.MONGO_RESULT_STORAGE_SERVER_URI
|
|
27
|
+
db_name=self.context.config.MONGO_RESULT_STORAGE_SERVER_DB
|
|
28
|
+
col_name=self.context.config.MONGO_RESULT_STORAGE_SERVER_COLLECTION
|
|
29
|
+
except AttributeError:
|
|
30
|
+
logger.error("[RESULT_STORAGE] Parametres databases incomplet")
|
|
31
|
+
|
|
32
|
+
mongo_conn = MongoConnector(
|
|
33
|
+
db_name=db_name,
|
|
34
|
+
col_name=col_name,
|
|
35
|
+
uri=uri,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
database = mongo_conn.db_conn
|
|
39
|
+
storage = mongo_conn.col_conn
|
|
40
|
+
|
|
41
|
+
return database, storage
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def is_auto_webp(self):
|
|
46
|
+
'''Return if webp.
|
|
47
|
+
:return: If the file is a webp
|
|
48
|
+
:rettype: boolean
|
|
49
|
+
'''
|
|
50
|
+
|
|
51
|
+
return self.context.config.AUTO_WEBP \
|
|
52
|
+
and self.context.request.accepts_webp
|
|
53
|
+
|
|
54
|
+
def get_key_from_request(self):
|
|
55
|
+
'''Return a path key for the current request url.
|
|
56
|
+
:return: The storage key for the current url
|
|
57
|
+
:rettype: string
|
|
58
|
+
'''
|
|
59
|
+
|
|
60
|
+
path = f"result:{self.context.request.url}"
|
|
61
|
+
|
|
62
|
+
if self.is_auto_webp:
|
|
63
|
+
return f'{path}/webp'
|
|
64
|
+
|
|
65
|
+
return path
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def get_max_age(self):
|
|
69
|
+
|
|
70
|
+
return self.context.config.RESULT_STORAGE_EXPIRATION_SECONDS
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
async def put(self, image_bytes):
|
|
74
|
+
key = self.get_key_from_request()
|
|
75
|
+
#max_age = self.get_max_age()
|
|
76
|
+
#result_ttl = self.get_max_age()
|
|
77
|
+
ref_img = ''
|
|
78
|
+
ref_img = re.findall(r'/[a-zA-Z0-9]{24}(?:$|/)', key)
|
|
79
|
+
if ref_img:
|
|
80
|
+
ref_img2 = ref_img[0].replace('/','')
|
|
81
|
+
else:
|
|
82
|
+
ref_img2 = 'undef'
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
if self.context.config.get("MONGO_STORE_METADATA", False):
|
|
86
|
+
metadata = dict(self.context.headers)
|
|
87
|
+
else:
|
|
88
|
+
metadata = {}
|
|
89
|
+
|
|
90
|
+
try:
|
|
91
|
+
listeProduit = self.context.config.PRODUIT
|
|
92
|
+
produit=''
|
|
93
|
+
for s in listeProduit:
|
|
94
|
+
if key.find(s) >= 1:
|
|
95
|
+
produit=s.replace('/', '')
|
|
96
|
+
break
|
|
97
|
+
else:
|
|
98
|
+
produit="info"
|
|
99
|
+
except AttributeError:
|
|
100
|
+
produit = 'undef'
|
|
101
|
+
|
|
102
|
+
doc = {
|
|
103
|
+
'path': key,
|
|
104
|
+
'created_at': datetime.utcnow(),
|
|
105
|
+
'data': Binary(image_bytes),
|
|
106
|
+
'metadata': metadata,
|
|
107
|
+
'content_type': BaseEngine.get_mimetype(image_bytes),
|
|
108
|
+
'ref_id': ref_img2,
|
|
109
|
+
'content_length' : len(image_bytes),
|
|
110
|
+
'produit': produit
|
|
111
|
+
}
|
|
112
|
+
doc_cpm = dict(doc)
|
|
113
|
+
|
|
114
|
+
await self.storage.insert_one(doc_cpm)
|
|
115
|
+
#return self.context.request.url
|
|
116
|
+
return key
|
|
117
|
+
|
|
118
|
+
async def get(self):
|
|
119
|
+
key = self.get_key_from_request()
|
|
120
|
+
logger.debug("[RESULT_STORAGE] image not found at %s", key)
|
|
121
|
+
|
|
122
|
+
print(key)
|
|
123
|
+
age = datetime.utcnow() - timedelta(
|
|
124
|
+
seconds=self.get_max_age()
|
|
125
|
+
)
|
|
126
|
+
stored = await self.storage.find_one({
|
|
127
|
+
'path': key,
|
|
128
|
+
'created_at': {
|
|
129
|
+
'$gte': age
|
|
130
|
+
},
|
|
131
|
+
}, {
|
|
132
|
+
'ref_id': True,
|
|
133
|
+
'created_at': True,
|
|
134
|
+
'metadata': True,
|
|
135
|
+
'content_type': True,
|
|
136
|
+
'data' : True,
|
|
137
|
+
'content_length': True,
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
if not stored:
|
|
142
|
+
return None
|
|
143
|
+
|
|
144
|
+
try:
|
|
145
|
+
#self.context.config.MONGO_RESULT_STORAGE_MAXCACHESIZE
|
|
146
|
+
dedup = self.context.config.MONGO_RESULT_STORAGE_DEDUP
|
|
147
|
+
except:
|
|
148
|
+
dedup = False
|
|
149
|
+
|
|
150
|
+
if not dedup:
|
|
151
|
+
logger.debug("Deduplication OFF")
|
|
152
|
+
else:
|
|
153
|
+
filter={
|
|
154
|
+
'path': key
|
|
155
|
+
}
|
|
156
|
+
sort=list({
|
|
157
|
+
'created_at': -1
|
|
158
|
+
}.items())
|
|
159
|
+
skip=1
|
|
160
|
+
obj = self.storage.find(filter=filter, skip=skip)
|
|
161
|
+
async for doc in obj:
|
|
162
|
+
logger.info("Deduplication %s", key)
|
|
163
|
+
self.storage.delete_one({"_id": doc["_id"]})
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
metadata = stored['metadata']
|
|
167
|
+
metadata['LastModified'] = stored['created_at'].replace(
|
|
168
|
+
tzinfo=pytz.utc
|
|
169
|
+
)
|
|
170
|
+
metadata['Cache-Control'] = "max-age=60,public"
|
|
171
|
+
metadata['ContentLength'] = stored['content_length']
|
|
172
|
+
metadata['ContentType'] = stored['content_type']
|
|
173
|
+
|
|
174
|
+
return ResultStorageResult(
|
|
175
|
+
buffer=stored['data'],
|
|
176
|
+
metadata=metadata,
|
|
177
|
+
successful=True
|
|
178
|
+
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: thumbor_libs_blackhand
|
|
3
|
+
Version: 0.5.1
|
|
4
|
+
Summary: libs thumbor
|
|
5
|
+
Home-page: https://github.com/Bkhand/thumbor_libs_blackhand
|
|
6
|
+
Author: Bertrand Thill
|
|
7
|
+
Author-email: github@blackhand.org
|
|
8
|
+
License: GNU
|
|
9
|
+
Keywords: thumbor,fallback,images,nfs,mongodb
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Natural Language :: French
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
17
|
+
Classifier: Topic :: Multimedia :: Graphics :: Presentation
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: thumbor>=7.7.0
|
|
20
|
+
Requires-Dist: pymongo>=4.2.0
|
|
21
|
+
Dynamic: author
|
|
22
|
+
Dynamic: author-email
|
|
23
|
+
Dynamic: classifier
|
|
24
|
+
Dynamic: description
|
|
25
|
+
Dynamic: home-page
|
|
26
|
+
Dynamic: keywords
|
|
27
|
+
Dynamic: license
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
Dynamic: requires-dist
|
|
30
|
+
Dynamic: summary
|
|
31
|
+
|
|
32
|
+
This module enable mongodb support and fallback for thumbor.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
thumbor_libs_blackhand.egg-info/PKG-INFO
|
|
5
|
+
thumbor_libs_blackhand.egg-info/SOURCES.txt
|
|
6
|
+
thumbor_libs_blackhand.egg-info/dependency_links.txt
|
|
7
|
+
thumbor_libs_blackhand.egg-info/requires.txt
|
|
8
|
+
thumbor_libs_blackhand.egg-info/top_level.txt
|
|
9
|
+
thumbor_libs_blackhand/loaders/__init__.py
|
|
10
|
+
thumbor_libs_blackhand/loaders/mongodb_loader.py
|
|
11
|
+
thumbor_libs_blackhand/loaders/spec_http_or_specb_loader.py
|
|
12
|
+
thumbor_libs_blackhand/loaders/specb_file_fallback_file_loader.py
|
|
13
|
+
thumbor_libs_blackhand/metrics/__init__.py
|
|
14
|
+
thumbor_libs_blackhand/mongodb/pool_result_storage.py
|
|
15
|
+
thumbor_libs_blackhand/result_storages/__init__.py
|
|
16
|
+
thumbor_libs_blackhand/result_storages/hybrid_result_storage.py
|
|
17
|
+
thumbor_libs_blackhand/result_storages/mongodb_result_storage_v3.py
|
|
18
|
+
thumbor_libs_blackhand/result_storages/mongodb_result_storage_v4.py
|
|
19
|
+
thumbor_libs_blackhand/result_storages/mongodb_result_storage_v5.py
|
|
20
|
+
thumbor_libs_blackhand/storages/__init__.py
|
|
21
|
+
thumbor_libs_blackhand/storages/mongodb_webp_storage.py
|
|
22
|
+
thumbor_libs_blackhand/url_signers/__init__.py
|
|
23
|
+
thumbor_libs_blackhand/url_signers/base64_hmac_sha1_trim.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
thumbor_libs_blackhand
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|