Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chaos Parcel Service
backend
Commits
f15e88f3
Verified
Commit
f15e88f3
authored
1 year ago
by
hanfi
Browse files
Options
Downloads
Patches
Plain Diff
allow register packages by image
parent
2738392f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+3
-0
3 additions, 0 deletions
.gitignore
backend/main.py
+12
-1
12 additions, 1 deletion
backend/main.py
backend/utils.py
+20
-0
20 additions, 0 deletions
backend/utils.py
with
35 additions
and
1 deletion
.gitignore
+
3
−
0
View file @
f15e88f3
...
@@ -35,3 +35,6 @@ venv.bak/
...
@@ -35,3 +35,6 @@ venv.bak/
# SQLite Databases
# SQLite Databases
*.db
*.db
# images directory
images/
This diff is collapsed.
Click to expand it.
backend/main.py
+
12
−
1
View file @
f15e88f3
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
from
uuid
import
UUID
from
uuid
import
UUID
from
fastapi
import
Depends
,
FastAPI
,
HTTPException
,
Request
,
status
from
fastapi
import
Depends
,
FastAPI
,
HTTPException
,
Request
,
UploadFile
,
status
from
fastapi.middleware.cors
import
CORSMiddleware
from
fastapi.middleware.cors
import
CORSMiddleware
from
fastapi.security
import
OAuth2PasswordBearer
,
OAuth2PasswordRequestForm
from
fastapi.security
import
OAuth2PasswordBearer
,
OAuth2PasswordRequestForm
from
itsdangerous.serializer
import
Serializer
from
itsdangerous.serializer
import
Serializer
...
@@ -67,6 +67,17 @@ def add_item(
...
@@ -67,6 +67,17 @@ def add_item(
return
utils
.
prepare_item_shipping
(
db
,
item
)
return
utils
.
prepare_item_shipping
(
db
,
item
)
@app.post
(
"
/item/register
"
,
response_model
=
schemas
.
Item
)
def
add_item_with_image
(
image
:
UploadFile
,
token
:
str
=
Depends
(
oauth2_scheme
),
db
:
Session
=
Depends
(
get_db
),
):
check_token
(
token
)
print
(
image
.
file
)
return
utils
.
add_item_with_image
(
db
,
image
)
@app.post
(
"
/item/update/{item_uuid}
"
,
response_model
=
schemas
.
Item
)
@app.post
(
"
/item/update/{item_uuid}
"
,
response_model
=
schemas
.
Item
)
def
update_item
(
def
update_item
(
item_uuid
:
str
,
data
:
schemas
.
ItemUpdate
,
db
:
Session
=
Depends
(
get_db
)
item_uuid
:
str
,
data
:
schemas
.
ItemUpdate
,
db
:
Session
=
Depends
(
get_db
)
...
...
This diff is collapsed.
Click to expand it.
backend/utils.py
+
20
−
0
View file @
f15e88f3
from
datetime
import
datetime
from
datetime
import
datetime
from
html
import
escape
from
html
import
escape
from
secrets
import
token_hex
from
secrets
import
token_hex
from
shutil
import
copyfileobj
from
tempfile
import
SpooledTemporaryFile
from
cryptography.exceptions
import
InvalidSignature
from
cryptography.exceptions
import
InvalidSignature
from
cryptography.hazmat.primitives.asymmetric.ed448
import
Ed448PublicKey
from
cryptography.hazmat.primitives.asymmetric.ed448
import
Ed448PublicKey
...
@@ -53,6 +55,24 @@ def prepare_item_shipping(db: Session, item: schemas.ItemCreatePrepareShipping):
...
@@ -53,6 +55,24 @@ def prepare_item_shipping(db: Session, item: schemas.ItemCreatePrepareShipping):
return
new_item
return
new_item
def
add_item_with_image
(
db
:
Session
,
image
:
SpooledTemporaryFile
):
db_item
=
models
.
Item
()
db
.
add
(
db_item
)
db
.
commit
()
db_image
=
models
.
Image
(
item_uuid
=
db_item
.
uuid
)
db
.
add
(
db_image
)
db
.
commit
()
db
.
refresh
(
db_image
)
print
(
db_item
.
uuid
)
print
(
db_image
.
uuid
)
with
open
(
f
"
./images/
{
db_image
.
uuid
}
"
,
"
wb
"
)
as
destination
:
try
:
copyfileobj
(
image
.
file
,
destination
)
finally
:
image
.
file
.
close
return
db_item
def
update_item
(
db
:
Session
,
item
:
schemas
.
Item
,
data
:
schemas
.
ItemUpdate
):
def
update_item
(
db
:
Session
,
item
:
schemas
.
Item
,
data
:
schemas
.
ItemUpdate
):
public_key
=
Ed448PublicKey
.
from_public_bytes
(
bytes
.
fromhex
(
item
.
verification
))
public_key
=
Ed448PublicKey
.
from_public_bytes
(
bytes
.
fromhex
(
item
.
verification
))
verify
=
""
verify
=
""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment