Skip to content

Commit a73e56a

Browse files
authored
Merge pull request #21 from JexPY/hotfix/dataFromUrl
Hotfix/data from url
2 parents 3ad3c76 + 37cbbca commit a73e56a

File tree

7 files changed

+30
-19
lines changed

7 files changed

+30
-19
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ certbot/letsecrypt/
88
key.json
99
docker-compose.yml
1010
nginx/sites/app.conf
11-
static/
1211
__pycache__/
1312
*.pyc
1413
.pytest_cache

api/app/.env-example

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SERVER
22
API_URL=http://localhost/
3+
# several separate with ,
34
FILE_MANAGER_BEARER_TOKEN=very_secret,any_more_secret_tokens
45
# several separate with ,
56
CORS_ORIGINS=http://localhost,http://ff.etomer.io
@@ -55,12 +56,13 @@ QR_IMAGE_LOCAL_PATH=static/qr/
5556

5657
# IMAGES
5758
IMAGE_CONVERTING_PREFERED_FORMAT=webp
58-
THUMBNAIL_MAX_WIDHT=320
59+
IMAGE_AllOWED_FILE_FORMAT=png,jpeg,jpg,webp
5960
# make thumbnails or nah True/False
6061
IMAGE_THUMBNAIL=True
62+
THUMBNAIL_MAX_WIDHT=320
6163
# suported:pillow-simd,ffmpeg
6264
# default:pillow-simd
63-
IMAGE_OPTIMIZATION_USING=ffmpeg
65+
IMAGE_OPTIMIZATION_USING=pillow-simd
6466

6567

6668
# VIDEOS

api/app/main.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def root(
5151
result['cpu_average_load'] = os.getloadavg()
5252
return result
5353

54+
5455
# File size validates NGINX
5556
@app.post("/image", tags=["image"])
5657
async def upload_image_file(
@@ -63,6 +64,7 @@ async def upload_image_file(
6364
OAuth2AuthorizationCodeBearer = Depends(validate_token)):
6465
return handle_upload_image_file(True if thumbnail == 'True' else False, file)
6566

67+
6668
@app.post("/images", tags=["image"])
6769
async def upload_image_files(
6870
thumbnail: Optional[str] = Query(
@@ -81,6 +83,7 @@ async def upload_image_files(
8183
)
8284
return handle_multiple_image_file_uploads(files, fileAmount, True if thumbnail == 'True' else False)
8385

86+
8487
@app.get("/image", tags=["image"])
8588
async def get_image(
8689
image: str = Query(...,
@@ -96,6 +99,7 @@ async def get_image(
9699
):
97100
return response_image_file(image, image_type)
98101

102+
99103
@app.post("/qrImage", tags=["image"])
100104
async def text_to_generate_qr_image(
101105
qr_text: str = Query(
@@ -138,20 +142,6 @@ async def image_from_url(
138142
OAuth2AuthorizationCodeBearer = Depends(validate_token)):
139143
return handle_download_data_from_url(image_url, True if thumbnail == 'True' else False, file_type='image')
140144

141-
@app.get("/videoUrl", tags=["from url"])
142-
async def video_from_url(
143-
video_url: str = Query(
144-
None,
145-
description = "Pass valid video url to upload",
146-
min_length = 5
147-
),
148-
optimize: Optional[str] = Query(
149-
os.environ.get('VIDEO_OPTIMIZE'),
150-
description='True/False depending your needs default is {}'.format(os.environ.get('VIDEO_OPTIMIZE')),
151-
regex='^(True|False)$'
152-
),
153-
OAuth2AuthorizationCodeBearer = Depends(validate_token)):
154-
return handle_download_data_from_url(video_url, True if optimize == 'True' else False, file_type='video')
155145

156146
@app.get("/imageUrls", tags=["from url"])
157147
async def images_from_urls(
@@ -167,4 +157,20 @@ async def images_from_urls(
167157
status_code=status.HTTP_413_REQUEST_ENTITY_TOO_LARGE,
168158
detail='Amount of files must not be more than {}'.format(os.environ.get('MULTIPLE_FILE_UPLOAD_LIMIT'))
169159
)
170-
return handle_multiple_image_file_downloads(image_urls, fileAmount)
160+
return handle_multiple_image_file_downloads(image_urls, fileAmount)
161+
162+
163+
@app.get("/videoUrl", tags=["from url"])
164+
async def video_from_url(
165+
video_url: str = Query(
166+
None,
167+
description = "Pass valid video url to upload",
168+
min_length = 5
169+
),
170+
optimize: Optional[str] = Query(
171+
os.environ.get('VIDEO_OPTIMIZE'),
172+
description='True/False depending your needs default is {}'.format(os.environ.get('VIDEO_OPTIMIZE')),
173+
regex='^(True|False)$'
174+
),
175+
OAuth2AuthorizationCodeBearer = Depends(validate_token)):
176+
return handle_download_data_from_url(video_url, False, True if optimize == 'True' else False, file_type='video')

api/app/services/serveUploadedFiles.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def handle_upload_image_file(thumbnail, upload_file: None, raw_data_file = None)
6161
imagePaths['thumbnail'] = os.environ.get('API_URL') + os.environ.get('IMAGE_THUMBNAIL_LOCAL_PATH') + imagePaths['thumbnail'] if imagePaths.get('thumbnail') else None
6262

6363
imagePaths['storage'] = os.environ.get('PREFERED_STORAGE')
64+
imagePaths['file_name'] = imagePaths['original'].split('/')[-1]
6465
return imagePaths
6566
else:
6667
raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail='The file format not supported')
@@ -106,6 +107,7 @@ def handle_upload_video_file(optimize, upload_file: None, raw_data_file = None):
106107
videoPaths['optimized'] = os.environ.get('API_URL') + os.environ.get('VIDEO_OPTIMIZED_LOCAL_PATH') + videoPaths['optimized'] if videoPaths.get('optimized') else None
107108

108109
videoPaths['storage'] = os.environ.get('PREFERED_STORAGE')
110+
videoPaths['file_name'] = videoPaths['original'].split('/')[-1]
109111

110112
return videoPaths
111113
else:
143 KB
Loading
Binary file not shown.

readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ Long story short, I needed microservice that would manage the files, so I ended
2525

2626
Here's what features FF has at this time:
2727
* Uploading image file/files
28+
* Downloading image file/files, from any image url
2829
* Image file/files optimization/converting using Pillow-SIMD or FFMPEG
2930
- You can have both installed or you can choose any of engines depending your needs
3031
* Uploading video file
32+
* Downloading video file, from any video url
3133
* Video file optimization/converting using FFMPEG
3234
- change in .env INSTALL_FFMPEG=false to INSTALL_FFMPEG=true
3335
- Then run
@@ -87,7 +89,7 @@ docker-compose up
8789
```
8890
- p.s You can create as much tokens as you want just separate them with ,
8991

90-
![](api/app/static/pictures/original/ef79f4dd65974d268e5ca2013a54edf.png?raw=true)
92+
![](api/app/static/pictures/original/afba38beae434b9fb4691bf8559947aa.png?raw=true)
9193

9294
### Installation for docker swarm
9395
- If you’re trying things out on a local development environment, you can put your engine into swarm mode with docker swarm init.

0 commit comments

Comments
 (0)