33 lines
646 B
Go
33 lines
646 B
Go
|
|
package uploadfiles
|
||
|
|
|
||
|
|
import (
|
||
|
|
"emperror.dev/errors"
|
||
|
|
"github.com/barasher/go-exiftool"
|
||
|
|
"lmika.dev/lmika/weiro/models"
|
||
|
|
)
|
||
|
|
|
||
|
|
func (p *Provider) StripeEXIFData(site models.Site, up models.Upload) error {
|
||
|
|
uploadFilename := p.uploadFileName(site, up)
|
||
|
|
|
||
|
|
et, err := exiftool.NewExiftool()
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
defer et.Close()
|
||
|
|
|
||
|
|
fileInfos := et.ExtractMetadata(uploadFilename)
|
||
|
|
if len(fileInfos) == 0 {
|
||
|
|
return errors.New("no exif data found")
|
||
|
|
}
|
||
|
|
fileInfo := fileInfos[0]
|
||
|
|
fileInfo.ClearAll()
|
||
|
|
|
||
|
|
fileOut := []exiftool.FileMetadata{fileInfo}
|
||
|
|
et.WriteMetadata(fileOut)
|
||
|
|
if fileOut[0].Err != nil {
|
||
|
|
return fileOut[0].Err
|
||
|
|
}
|
||
|
|
|
||
|
|
return nil
|
||
|
|
}
|