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
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
84f07d55
Commit
84f07d55
authored
3 years ago
by
Ophestra
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of craft.chars.jp:/srv/git/image-board
parents
1342f0ab
3df7e6f7
No related branches found
Branches containing commit
Tags
v0.7.3
Tags containing commit
No related merge requests found
Changes
2
Hide 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 @
84f07d55
...
...
@@ -294,6 +294,42 @@ func registerAPI() {
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
)
{
info
,
ok
:=
getUser
(
context
)
...
...
This diff is collapsed.
Click to expand it.
store/image.go
+
6
−
0
View file @
84f07d55
...
...
@@ -64,6 +64,9 @@ func (s *Store) Image(hash string) Image {
func
(
s
*
Store
)
ImageMetadataRead
(
path
string
)
Image
{
var
metadata
Image
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
))
}
else
{
if
err
=
json
.
Unmarshal
(
payload
,
&
metadata
);
err
!=
nil
{
...
...
@@ -246,6 +249,9 @@ func (s *Store) ImageSnowflakeHash(flake string) string {
return
s
.
ImageMetadataRead
(
s
.
ImageSnowflakePath
(
flake
)
+
"/"
+
infoJson
)
.
Hash
}
else
{
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
))
}
else
{
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