Skip to content

Commit

Permalink
FIX: file MIME content-type
Browse files Browse the repository at this point in the history
  • Loading branch information
rigon committed Jul 5, 2023
1 parent 5647fc6 commit 594fa4c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 16 deletions.
3 changes: 1 addition & 2 deletions server/file.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"bufio"
"errors"
"image"
"io"
Expand Down Expand Up @@ -196,7 +195,7 @@ func (file *File) RequiresConvertion() bool {
return false
}

func (file *File) Convert(w *bufio.Writer) error {
func (file *File) Convert(w io.Writer) error {
switch file.Type {
case "image":
// Check for EXIF
Expand Down
8 changes: 4 additions & 4 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ require (
github.com/timshannon/bolthold v0.0.0-20210913165410-232392fc8a6a
gitlab.com/golang-utils/image2 v0.0.1
go.etcd.io/bbolt v1.3.7
golang.org/x/image v0.8.0
golang.org/x/net v0.11.0
golang.org/x/image v0.9.0
golang.org/x/net v0.12.0
)

require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/klauspost/compress v1.16.6 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
Expand All @@ -37,5 +37,5 @@ require (
github.com/valyala/fasthttp v1.48.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/sys v0.10.0 // indirect
)
9 changes: 9 additions & 0 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/klauspost/compress v1.16.6 h1:91SKEy4K37vkp255cJ8QesJhjyRO0hn9i9G0GoUwLsk=
github.com/klauspost/compress v1.16.6/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
Expand Down Expand Up @@ -78,6 +80,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.8.0 h1:agUcRXV/+w6L9ryntYYsF2x9fQTMd4T8fiiYXAVW6Jg=
golang.org/x/image v0.8.0/go.mod h1:PwLxp3opCYg4WR2WO9P0L6ESnsD6bLTWcw8zanLMVFM=
golang.org/x/image v0.9.0 h1:QrzfX26snvCM20hIhBwuHI/ThTg18b/+kcKdXHvnR+g=
golang.org/x/image v0.9.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
Expand All @@ -91,6 +95,8 @@ golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -110,6 +116,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
Expand All @@ -120,6 +128,7 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
Expand Down
6 changes: 3 additions & 3 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ func file(c *fiber.Ctx) error {
return nil
}

c.Set("Content-Type", file.Type)
c.Set("Content-Disposition", "attachment; filename=\""+file.Name()+"\"")
c.Set("Content-Type", file.MIME)
c.Set("Content-Disposition", "inline; filename=\""+file.Name()+"\"")
return c.SendFile(file.Path)
}

Expand Down Expand Up @@ -261,7 +261,7 @@ func main() {
api.Get("/pseudos", pseudos)
api.Get("/collections", collections)
api.Get("/collection/:collection/albums", albums)
api.Put("/collection/:collection/album", addAlbum)
api.Put("/collection/:collection/albums", addAlbum)
api.Get("/collection/:collection/album/:album", album)
api.Get("/collection/:collection/album/:album/photo/:photo/thumb", thumb)
api.Get("/collection/:collection/album/:album/photo/:photo/info", info)
Expand Down
4 changes: 2 additions & 2 deletions src/Gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const iconsStyle: CSSProperties = {
};

const Gallery: FC = () => {
const { collection, album } = useParams();
const { collection = "", album = ""} = useParams();
const { data, isFetching } = useGetAlbumQuery({collection, album});
const [ lightboxIndex, setLightboxIndex ] = useState<number>(-1);
const [ infoPhotoIndex, setInfoPhotoIndex ] = useState<number>(-1);
Expand All @@ -60,7 +60,7 @@ const Gallery: FC = () => {
errorNotification("No favorite album is selected. Select first from the top toolbar.");
return;
}
if(collection === undefined || album === undefined || index >= photos.length) {
if(collection === "" || album === "" || index < 0 || index >= photos.length) {
errorNotification("Select a collection and an album from the left menu.");
return;
}
Expand Down
12 changes: 7 additions & 5 deletions src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export interface QueryAlbums {
}

export interface QueryAlbum {
collection?: string;
album?: string;
collection: string;
album: string;
}

export interface QueryAddAlbum {
Expand All @@ -35,6 +35,8 @@ export interface QuerySaveFavorite {
}
}

const albumId = (arg: { collection: string, album: string }) => arg.collection + ":" + arg.album;

export const api = createApi({
baseQuery: fetchBaseQuery({ baseUrl: '/api' }),
tagTypes: ['Album', 'Albums', 'Pseudo'],
Expand All @@ -55,11 +57,11 @@ export const api = createApi({
}),
getAlbum: builder.query<AlbumType, QueryAlbum>({
query: ({ collection, album }) => `/collection/${collection}/album/${album}`,
providesTags: (_result, _error, arg) => [{ type: 'Album', id: `${arg.collection}:${arg.album}` }],
providesTags: (_result, _error, arg) => [{ type: 'Album', id: albumId(arg) }],
}),
addAlbum: builder.mutation<void, QueryAddAlbum>({
query: ({ collection, ...body }) => ({
url: `/collection/${collection}/album`,
url: `/collection/${collection}/albums`,
method: 'PUT',
body,
}),
Expand All @@ -74,7 +76,7 @@ export const api = createApi({
method: favorite ? 'PUT' : 'DELETE',
body: saveData,
}),
invalidatesTags: (_result, _error, arg) => [{ type: 'Album', id: `${arg.collection}:${arg.album}` }],
invalidatesTags: (_result, _error, arg) => [{ type: 'Album', id: albumId(arg) }],
async onQueryStarted({ collection, album, saveData, photoIndex, favorite }, { dispatch, queryFulfilled }) {
const query: QueryAlbum = { collection: saveData.collection, album: saveData.album };
const patchResult = dispatch(
Expand Down

0 comments on commit 594fa4c

Please sign in to comment.