mirror of
https://github.com/Cernobor/oko-server.git
synced 2025-02-24 08:27:17 +00:00
thumbnail content type
* content type of thumbnail is separated from the full photo content type * remove git from build dependencies in Dockerfile
This commit is contained in:
parent
1cf44e3bfc
commit
7506421848
@ -3,9 +3,9 @@ FROM alpine:3.15.0 AS build
|
||||
VOLUME ["/data"]
|
||||
COPY . /oko-server/git
|
||||
|
||||
RUN apk add --no-cache go git && \
|
||||
RUN apk add --no-cache go && \
|
||||
cd /oko-server/git && \
|
||||
go build -ldflags "-X \"main.sha1ver=$(git rev-parse HEAD)\" -X \"main.buildTime=$(date -Iseconds)\""
|
||||
go build -ldflags "-X \"main.sha1ver=$(cat .git/$(cat .git/HEAD | sed 's|ref: ||g'))\" -X \"main.buildTime=$(date -Iseconds)\""
|
||||
|
||||
FROM alpine:3.15.0
|
||||
WORKDIR /oko-server
|
||||
|
@ -87,6 +87,7 @@ type Photo struct {
|
||||
|
||||
type PhotoMetadata struct {
|
||||
ContentType string `json:"content_type"`
|
||||
ThumbnailContentType string `json:"thumbnail_content_type"`
|
||||
Size int64 `json:"size"`
|
||||
ID FeaturePhotoID `json:"id"`
|
||||
ThumbnailFilename string `json:"thumbnail_filename"`
|
||||
|
@ -19,7 +19,8 @@ DROP TABLE IF EXISTS feature_photos;
|
||||
CREATE TABLE IF NOT EXISTS feature_photos (
|
||||
id integer PRIMARY KEY AUTOINCREMENT,
|
||||
feature_id integer NOT NULL REFERENCES features(id) ON DELETE CASCADE,
|
||||
thumbnail_content_type text NOT NULL,
|
||||
content_type text NOT NULL,
|
||||
thumbnail_contents blob NOT NULL,
|
||||
file_contents blob NOT NULL
|
||||
contents blob NOT NULL
|
||||
);
|
@ -241,7 +241,7 @@ func (s *Server) getDataWithPhotos() (file *os.File, err error) {
|
||||
}
|
||||
|
||||
data.PhotoMetadata = make(map[string]models.PhotoMetadata, 100)
|
||||
err = sqlitex.Exec(conn, "select id, content_type, length(file_contents) from feature_photos", func(stmt *sqlite.Stmt) error {
|
||||
err = sqlitex.Exec(conn, "select id, content_type, length(contents) from feature_photos", func(stmt *sqlite.Stmt) error {
|
||||
id := models.FeaturePhotoID(stmt.ColumnInt64(0))
|
||||
contentType := stmt.ColumnText(1)
|
||||
fileSize := stmt.ColumnInt64(2)
|
||||
@ -301,7 +301,7 @@ func (s *Server) getDataWithPhotos() (file *os.File, err error) {
|
||||
return fmt.Errorf("failed to write photo ID %d thumbnail: %w", id, err)
|
||||
}
|
||||
|
||||
blob, err = conn.OpenBlob("", "feature_photos", "file_contents", id, false)
|
||||
blob, err = conn.OpenBlob("", "feature_photos", "contents", id, false)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open photo ID %d photo content blob: %w", id, err)
|
||||
}
|
||||
@ -540,7 +540,7 @@ func (s *Server) addFeatures(conn *sqlite.Conn, features []models.Feature) (map[
|
||||
}
|
||||
|
||||
func (s *Server) addPhotos(conn *sqlite.Conn, createdFeatureMapping, addedFeatureMapping map[models.FeatureID][]string, createdIDMapping map[models.FeatureID]models.FeatureID, photos map[string]models.Photo) error {
|
||||
stmt, err := conn.Prepare("insert into feature_photos(feature_id, content_type, thumbnail_contents, file_contents) values(?, ?, ?, ?)")
|
||||
stmt, err := conn.Prepare("insert into feature_photos(feature_id, thumbnail_content_type, content_type, thumbnail_contents, contents) values(?, ?, ?, ?, ?)")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to prepare statement: %w", err)
|
||||
}
|
||||
@ -570,9 +570,10 @@ func (s *Server) addPhotos(conn *sqlite.Conn, createdFeatureMapping, addedFeatur
|
||||
}
|
||||
|
||||
stmt.BindInt64(1, int64(featureID))
|
||||
stmt.BindText(2, photo.ContentType)
|
||||
stmt.BindZeroBlob(3, thumbnail.Size)
|
||||
stmt.BindZeroBlob(4, photo.Size)
|
||||
stmt.BindText(2, thumbnail.ContentType)
|
||||
stmt.BindText(3, photo.ContentType)
|
||||
stmt.BindZeroBlob(4, thumbnail.Size)
|
||||
stmt.BindZeroBlob(5, photo.Size)
|
||||
|
||||
_, err = stmt.Step()
|
||||
if err != nil {
|
||||
@ -594,7 +595,7 @@ func (s *Server) addPhotos(conn *sqlite.Conn, createdFeatureMapping, addedFeatur
|
||||
return fmt.Errorf("failed to write to thumbnail content blob: %w", err)
|
||||
}
|
||||
|
||||
blob, err = conn.OpenBlob("", "feature_photos", "file_contents", conn.LastInsertRowID(), true)
|
||||
blob, err = conn.OpenBlob("", "feature_photos", "contents", conn.LastInsertRowID(), true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open photo content blob: %w", err)
|
||||
}
|
||||
@ -745,7 +746,7 @@ func (s *Server) getPhoto(featureID models.FeatureID, photoID models.FeaturePhot
|
||||
var contentType *string = nil
|
||||
var data []byte = nil
|
||||
found := false
|
||||
err := sqlitex.Exec(conn, "select content_type, file_contents from feature_photos where id = ? and feature_id = ?", func(stmt *sqlite.Stmt) error {
|
||||
err := sqlitex.Exec(conn, "select content_type, contents from feature_photos where id = ? and feature_id = ?", func(stmt *sqlite.Stmt) error {
|
||||
if found {
|
||||
return fmt.Errorf("multiple photos returned for feature id %d, photo id %d", featureID, photoID)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user