Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
imghost
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Janne Mareike Koschinski
imghost
Commits
455aa1ed
Commit
455aa1ed
authored
7 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Added more metadata about images
parent
9bd696ac
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
main.go
+26
-23
26 additions, 23 deletions
main.go
templates/me_images
+5
-2
5 additions, 2 deletions
templates/me_images
types.go
+11
-6
11 additions, 6 deletions
types.go
with
42 additions
and
31 deletions
main.go
+
26
−
23
View file @
455aa1ed
package
main
import
(
"os"
"net/http"
"io"
"path/filepath"
"encoding/json"
"github.com/go-redis/redis"
"fmt"
"encoding/base64"
"crypto/rand"
"time"
"database/sql"
"encoding/base64"
"encoding/json"
"fmt"
"github.com/go-redis/redis"
_
"github.com/lib/pq"
"html/template"
"io"
"mime/multipart"
"net/http"
"os"
"path/filepath"
"time"
)
func
writeBody
(
reader
io
.
ReadCloser
,
path
string
)
error
{
...
...
@@ -52,7 +53,7 @@ func generateId() string {
return
base64
.
URLEncoding
.
WithPadding
(
base64
.
NoPadding
)
.
EncodeToString
(
buffer
)
}
func
createImage
(
config
*
Config
,
body
io
.
ReadCloser
)
(
Image
,
error
)
{
func
createImage
(
config
*
Config
,
body
io
.
ReadCloser
,
fileHeader
*
multipart
.
FileHeader
)
(
Image
,
error
)
{
id
:=
generateId
()
path
:=
filepath
.
Join
(
config
.
SourceFolder
,
id
)
...
...
@@ -68,6 +69,8 @@ func createImage(config *Config, body io.ReadCloser) (Image, error) {
image
:=
Image
{
Id
:
id
,
OriginalName
:
filepath
.
Base
(
fileHeader
.
Filename
),
CreatedAt
:
time
.
Now
(),
MimeType
:
mimeType
,
}
return
image
,
nil
...
...
@@ -131,8 +134,8 @@ func main() {
user
:=
parseUser
(
r
)
r
.
ParseMultipartForm
(
32
<<
20
)
file
,
_
,
err
:=
r
.
FormFile
(
"file"
)
image
,
err
:=
createImage
(
&
config
,
file
)
file
,
fileheader
,
err
:=
r
.
FormFile
(
"file"
)
image
,
err
:=
createImage
(
&
config
,
file
,
fileheader
)
if
err
!=
nil
{
returnResult
(
w
,
Result
{
Id
:
""
,
...
...
@@ -142,7 +145,7 @@ func main() {
return
}
_
,
err
=
db
.
Exec
(
"INSERT INTO images (id, owner) VALUES ($1, $2)"
,
image
.
Id
,
user
.
Id
)
_
,
err
=
db
.
Exec
(
"INSERT INTO images (id, owner
, created_at, original_name, type
) VALUES ($1, $2
, $3, $4, $5
)"
,
image
.
Id
,
user
.
Id
,
image
.
CreatedAt
,
image
.
OriginalName
,
image
.
MimeType
)
if
err
!=
nil
{
panic
(
err
)
}
...
...
@@ -221,29 +224,29 @@ func main() {
type
ImageListData
struct
{
User
UserInfo
Images
[]
string
Images
[]
Image
}
result
,
err
:=
db
.
Query
(
"SELECT id FROM images WHERE owner = $1"
,
user
.
Id
)
result
,
err
:=
db
.
Query
(
"SELECT id
, title, description, created_at, original_name, type
FROM images WHERE owner = $1"
,
user
.
Id
)
if
err
!=
nil
{
panic
(
err
)
}
var
images
[]
string
var
images
[]
Image
for
result
.
Next
()
{
var
i
d
string
err
:=
result
.
Scan
(
&
i
d
)
var
i
nfo
Image
err
:=
result
.
Scan
(
&
i
nfo
.
Id
,
&
info
.
Title
,
&
info
.
Description
,
&
info
.
CreatedAt
,
&
info
.
OriginalName
,
&
info
.
MimeType
)
if
err
!=
nil
{
panic
(
err
)
}
images
=
append
(
images
,
i
d
)
images
=
append
(
images
,
i
nfo
)
}
tmpl
,
err
:=
template
.
New
(
"me_images"
)
.
ParseFiles
(
"templates/me_images"
)
t
e
mpl
ate
,
err
:=
template
.
New
(
"me_images"
)
.
ParseFiles
(
"templates/me_images"
)
if
err
!=
nil
{
panic
(
err
)
}
err
=
tmpl
.
Execute
(
w
,
ImageListData
{
err
=
t
e
mpl
ate
.
Execute
(
w
,
ImageListData
{
user
,
images
,
})
...
...
This diff is collapsed.
Click to expand it.
templates/me_images
+
5
−
2
View file @
455aa1ed
...
...
@@ -8,7 +8,10 @@
</p>
{{ range .Images }}
<a
href=
"/i/{{ . }}"
>
<img
src=
"/i/{{ . }}t"
>
<a
href=
"/i/{{ .Id }}"
>
<img
src=
"/i/{{ .Id }}t"
>
<p>
{{ .OriginalName }}
</p>
<p>
{{ .CreatedAt }}
</p>
<p>
{{ .MimeType }}
</p>
</a>
{{ end }}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
types.go
+
11
−
6
View file @
455aa1ed
package
main
import
(
"os"
"encoding/json"
"os"
"time"
)
type
Image
struct
{
Id
string
`json:"id"`
Title
string
Description
string
CreatedAt
time
.
Time
OriginalName
string
MimeType
string
`json:"mime_type"`
}
...
...
@@ -23,8 +28,8 @@ type Size struct {
}
const
(
SIZE_FORMAT_COVER
=
"cover"
SIZE_FORMAT_CONTAIN
=
"contain"
sizeFormatCover
=
"cover"
sizeFormatContain
=
"contain"
)
type
Quality
struct
{
...
...
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