mirror of
https://github.com/woodchen-ink/webp_server_go.git
synced 2025-07-18 13:42:02 +08:00
Remove metadata when original not exist, update support for heic (#266)
* Remove metadata when original not exist, update support for heic * Warnf to Warnln
This commit is contained in:
parent
ab4373263d
commit
d9da7f3cd3
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
This is a Server based on Golang, which allows you to serve WebP images on the fly.
|
This is a Server based on Golang, which allows you to serve WebP images on the fly.
|
||||||
|
|
||||||
Currently supported image format: JPEG, PNG, BMP, GIF, SVG
|
Currently supported image format: JPEG, PNG, BMP, GIF, SVG, HEIC
|
||||||
|
|
||||||
> e.g When you visit `https://your.website/pics/tsuki.jpg`,it will serve as `image/webp` format without changing the URL.
|
> e.g When you visit `https://your.website/pics/tsuki.jpg`,it will serve as `image/webp` format without changing the URL.
|
||||||
|
|
||||||
@ -35,6 +35,7 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./path/to/pics:/opt/pics
|
- ./path/to/pics:/opt/pics
|
||||||
- ./exhaust:/opt/exhaust
|
- ./exhaust:/opt/exhaust
|
||||||
|
- ./metadata:/opt/metadata
|
||||||
ports:
|
ports:
|
||||||
- 127.0.0.1:3333:3333
|
- 127.0.0.1:3333:3333
|
||||||
```
|
```
|
||||||
@ -49,6 +50,7 @@ Then
|
|||||||
|
|
||||||
* `./path/to/pics` should be changed to `/var/www/img.webp.sh`
|
* `./path/to/pics` should be changed to `/var/www/img.webp.sh`
|
||||||
* `./exhaust` is cache folder for output images, by default it will be in `exhaust` directory alongside with `docker-compose.yml` file, if you'd like to keep cached images in another folder, you can change `./exhaust` to `/some/other/path/to/exhaust`
|
* `./exhaust` is cache folder for output images, by default it will be in `exhaust` directory alongside with `docker-compose.yml` file, if you'd like to keep cached images in another folder, you can change `./exhaust` to `/some/other/path/to/exhaust`
|
||||||
|
* `./metadata` is cache folder for images' metadata, by default it will be in `metadata` directory alongside with `docker-compose.yml` file
|
||||||
|
|
||||||
Start the container using:
|
Start the container using:
|
||||||
|
|
||||||
@ -77,6 +79,7 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./path/to/pics:/opt/pics
|
- ./path/to/pics:/opt/pics
|
||||||
- ./path/to/exhaust:/opt/exhaust
|
- ./path/to/exhaust:/opt/exhaust
|
||||||
|
- ./path/to/metadata:/opt/metadata
|
||||||
- ./config.json:/etc/config.json
|
- ./config.json:/etc/config.json
|
||||||
ports:
|
ports:
|
||||||
- 127.0.0.1:3333:3333
|
- 127.0.0.1:3333:3333
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"QUALITY": "80",
|
"QUALITY": "80",
|
||||||
"IMG_PATH": "./pics",
|
"IMG_PATH": "./pics",
|
||||||
"EXHAUST_PATH": "./exhaust",
|
"EXHAUST_PATH": "./exhaust",
|
||||||
"ALLOWED_TYPES": ["jpg","png","jpeg","bmp","gif","svg"],
|
"ALLOWED_TYPES": ["jpg","png","jpeg","bmp","gif","svg","heic"],
|
||||||
"IMG_MAP": {},
|
"IMG_MAP": {},
|
||||||
"ENABLE_AVIF": false,
|
"ENABLE_AVIF": false,
|
||||||
"ENABLE_EXTRA_PARAMS": false
|
"ENABLE_EXTRA_PARAMS": false
|
||||||
|
@ -144,6 +144,7 @@ func Convert(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
// Check the original image for existence,
|
// Check the original image for existence,
|
||||||
if !helper.ImageExists(rawImageAbs) {
|
if !helper.ImageExists(rawImageAbs) {
|
||||||
|
helper.DeleteMetadata(reqURIwithQuery, targetHostName)
|
||||||
msg := "image not found"
|
msg := "image not found"
|
||||||
_ = c.Send([]byte(msg))
|
_ = c.Send([]byte(msg))
|
||||||
log.Warn(msg)
|
log.Warn(msg)
|
||||||
|
@ -68,3 +68,12 @@ func WriteMetadata(p, etag string, subdir string) config.MetaFile {
|
|||||||
_ = os.WriteFile(path.Join(config.Metadata, subdir, data.Id+".json"), buf, 0644)
|
_ = os.WriteFile(path.Join(config.Metadata, subdir, data.Id+".json"), buf, 0644)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeleteMetadata(p string, subdir string) {
|
||||||
|
var id, _, _ = getId(p)
|
||||||
|
metadataPath := path.Join(config.Metadata, subdir, id+".json")
|
||||||
|
err := os.Remove(metadataPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnln("failed to delete metadata", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user