Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
image board
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
random asynchronous nightmare distributor
image board
Commits
3df7e6f7
Commit
3df7e6f7
authored
Aug 3, 2021
by
Ophestra
Browse files
Options
Downloads
Patches
Plain Diff
image file get via snowflake, check if file not exist in snowflake lookup
parent
2e6ace1a
Branches
Branches containing commit
Tags
v0.7.2
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
api.go
+36
-0
36 additions, 0 deletions
api.go
store/image.go
+6
-0
6 additions, 0 deletions
store/image.go
with
42 additions
and
0 deletions
api.go
+
36
−
0
View file @
3df7e6f7
...
@@ -294,6 +294,42 @@ func registerAPI() {
...
@@ -294,6 +294,42 @@ func registerAPI() {
context
.
JSON
(
http
.
StatusOK
,
instance
.
ImageSnowflake
(
flake
))
context
.
JSON
(
http
.
StatusOK
,
instance
.
ImageSnowflake
(
flake
))
})
})
router
.
GET
(
"/api/image/snowflake/:flake/file"
,
func
(
context
*
gin
.
Context
)
{
flake
:=
context
.
Param
(
"flake"
)
if
_
,
err
:=
strconv
.
Atoi
(
flake
);
err
!=
nil
{
context
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"invalid snowflake"
,
})
return
}
image
,
data
:=
instance
.
ImageData
(
instance
.
ImageSnowflakeHash
(
flake
),
false
)
if
image
.
Hash
==
""
{
context
.
JSON
(
http
.
StatusNotFound
,
gin
.
H
{
"error"
:
"not found"
,
})
return
}
context
.
Data
(
http
.
StatusOK
,
"image/"
+
image
.
Type
,
data
)
})
router
.
GET
(
"/api/image/snowflake/:flake/preview"
,
func
(
context
*
gin
.
Context
)
{
flake
:=
context
.
Param
(
"flake"
)
if
_
,
err
:=
strconv
.
Atoi
(
flake
);
err
!=
nil
{
context
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
"invalid snowflake"
,
})
return
}
image
,
data
:=
instance
.
ImageData
(
instance
.
ImageSnowflakeHash
(
flake
),
true
)
if
image
.
Hash
==
""
{
context
.
JSON
(
http
.
StatusNotFound
,
gin
.
H
{
"error"
:
"not found"
,
})
return
}
context
.
Data
(
http
.
StatusOK
,
"image/jpeg"
,
data
)
})
router
.
GET
(
"/api/image"
,
func
(
context
*
gin
.
Context
)
{
router
.
GET
(
"/api/image"
,
func
(
context
*
gin
.
Context
)
{
info
,
ok
:=
getUser
(
context
)
info
,
ok
:=
getUser
(
context
)
...
...
This diff is collapsed.
Click to expand it.
store/image.go
+
6
−
0
View file @
3df7e6f7
...
@@ -64,6 +64,9 @@ func (s *Store) Image(hash string) Image {
...
@@ -64,6 +64,9 @@ func (s *Store) Image(hash string) Image {
func
(
s
*
Store
)
ImageMetadataRead
(
path
string
)
Image
{
func
(
s
*
Store
)
ImageMetadataRead
(
path
string
)
Image
{
var
metadata
Image
var
metadata
Image
if
payload
,
err
:=
os
.
ReadFile
(
path
);
err
!=
nil
{
if
payload
,
err
:=
os
.
ReadFile
(
path
);
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
return
Image
{}
}
s
.
fatalClose
(
fmt
.
Sprintf
(
"Error reading image metadata %s, %s"
,
path
,
err
))
s
.
fatalClose
(
fmt
.
Sprintf
(
"Error reading image metadata %s, %s"
,
path
,
err
))
}
else
{
}
else
{
if
err
=
json
.
Unmarshal
(
payload
,
&
metadata
);
err
!=
nil
{
if
err
=
json
.
Unmarshal
(
payload
,
&
metadata
);
err
!=
nil
{
...
@@ -246,6 +249,9 @@ func (s *Store) ImageSnowflakeHash(flake string) string {
...
@@ -246,6 +249,9 @@ func (s *Store) ImageSnowflakeHash(flake string) string {
return
s
.
ImageMetadataRead
(
s
.
ImageSnowflakePath
(
flake
)
+
"/"
+
infoJson
)
.
Hash
return
s
.
ImageMetadataRead
(
s
.
ImageSnowflakePath
(
flake
)
+
"/"
+
infoJson
)
.
Hash
}
else
{
}
else
{
if
path
,
err
:=
os
.
ReadFile
(
s
.
ImageSnowflakePath
(
flake
));
err
!=
nil
{
if
path
,
err
:=
os
.
ReadFile
(
s
.
ImageSnowflakePath
(
flake
));
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
return
""
}
s
.
fatalClose
(
fmt
.
Sprintf
(
"Error reading snowflake %s association file, %s"
,
flake
,
err
))
s
.
fatalClose
(
fmt
.
Sprintf
(
"Error reading snowflake %s association file, %s"
,
flake
,
err
))
}
else
{
}
else
{
return
s
.
ImageMetadataRead
(
string
(
path
)
+
"/"
+
infoJson
)
.
Hash
return
s
.
ImageMetadataRead
(
string
(
path
)
+
"/"
+
infoJson
)
.
Hash
...
...
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