-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fbf796
commit 0add099
Showing
13 changed files
with
227 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,24 @@ | ||
# LinguaPhoto | ||
|
||
## Getting Started | ||
|
||
First, start localstack, which lets you run AWS locally. | ||
|
||
Next, create tables using the command: | ||
|
||
```bash | ||
python -m linguaphoto.db | ||
``` | ||
|
||
Run the backend using the command: | ||
|
||
```bash | ||
uvicorn linguaphoto.main:app --reload | ||
``` | ||
|
||
Finally, run the frontend using the command: | ||
|
||
```bash | ||
cd frontend | ||
npm start | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Defines CRUD interface for images API.""" | ||
|
||
import uuid | ||
|
||
from linguaphoto.crud.base import BaseCrud | ||
from linguaphoto.settings import settings | ||
|
||
|
||
class ImagesCrud(BaseCrud): | ||
async def add_image(self, image_id: uuid.UUID, user_id: uuid.UUID, image: bytes) -> None: | ||
# Adds the image to the database. | ||
table = await self.db.Table("Images") | ||
await table.put_item(Item={"image_id": str(image_id), "user_id": str(user_id)}) | ||
|
||
# Uploads the image to S3. | ||
key = f"{user_id}/{image_id}" | ||
await self.s3.put_object(Bucket=settings.aws.image_bucket_id, Key=key, Body=image) | ||
|
||
async def delete_image(self, image_id: uuid.UUID, user_id: uuid.UUID) -> None: | ||
# Deletes the image from the database. | ||
table = await self.db.Table("Images") | ||
await table.delete_item(Key={"image_id": str(image_id), "user_id": str(user_id)}) | ||
|
||
# Deletes the image from S3. | ||
key = f"{user_id}/{image_id}.webp" | ||
await self.s3.delete_object(Bucket=settings.aws.image_bucket_id, Key=key) | ||
|
||
async def get_image_url(self, image_id: uuid.UUID, user_id: uuid.UUID) -> str | None: | ||
key = f"{user_id}/{image_id}.webp" | ||
|
||
# If CloudFront is enabled, gets the image URL from CloudFront. | ||
if settings.aws.cloudfront_url is not None: | ||
return await self.cf.generate_presigned_url( | ||
"get_object", | ||
Params={"Bucket": settings.aws.image_bucket_id, "Key": key}, | ||
ExpiresIn=3600, | ||
) | ||
|
||
# Gets the image URL from S3. | ||
url = await self.s3.generate_presigned_url( | ||
"get_object", | ||
Params={"Bucket": settings.aws.image_bucket_id, "Key": key}, | ||
ExpiresIn=3600, | ||
) | ||
return url |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,6 @@ s3fs | |
|
||
# Types | ||
types-requests | ||
|
||
# AWS | ||
localstack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,8 @@ crypto: | |
jwt_secret: fakeJwtSecret | ||
site: | ||
homepage: http://127.0.0.1:3000 | ||
image_bucket_id: linguaphoto-images | ||
user: | ||
test_user: | ||
email: [email protected] | ||
google_token: fakeGoogleToken |
Oops, something went wrong.