🔒 Fix Attachment will contains GPS information
This commit is contained in:
		
							
								
								
									
										2
									
								
								.idea/dataSources.local.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								.idea/dataSources.local.xml
									
									
									
										generated
									
									
									
								
							| @@ -1,6 +1,6 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project version="4"> | ||||
|   <component name="dataSourceStorageLocal" created-in="GO-242.21829.220"> | ||||
|   <component name="dataSourceStorageLocal" created-in="GO-242.23339.24"> | ||||
|     <data-source name="hy_paperclip@localhost" uuid="bac83d8a-c619-4680-a07f-6674b93fbfea"> | ||||
|       <database-info product="PostgreSQL" version="16.3 (Homebrew)" jdbc-version="4.2" driver-name="PostgreSQL JDBC Driver" driver-version="42.6.0" dbms="POSTGRES" exact-version="16.3" exact-driver-version="42.6"> | ||||
|         <identifier-quote-string>"</identifier-quote-string> | ||||
|   | ||||
							
								
								
									
										10
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										10
									
								
								.idea/workspace.xml
									
									
									
										generated
									
									
									
								
							| @@ -5,7 +5,13 @@ | ||||
|   </component> | ||||
|   <component name="ChangeListManager"> | ||||
|     <list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":sparkles: Attachment API can edit metadata"> | ||||
|       <change afterPath="$PROJECT_DIR$/pkg/test_exif.go" afterDir="false" /> | ||||
|       <change beforePath="$PROJECT_DIR$/.idea/dataSources.local.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dataSources.local.xml" afterDir="false" /> | ||||
|       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> | ||||
|       <change beforePath="$PROJECT_DIR$/Dockerfile" beforeDir="false" afterPath="$PROJECT_DIR$/Dockerfile" afterDir="false" /> | ||||
|       <change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" /> | ||||
|       <change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" /> | ||||
|       <change beforePath="$PROJECT_DIR$/pkg/internal/services/analyzer.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/analyzer.go" afterDir="false" /> | ||||
|     </list> | ||||
|     <option name="SHOW_DIALOG" value="false" /> | ||||
|     <option name="HIGHLIGHT_CONFLICTS" value="true" /> | ||||
| @@ -95,8 +101,8 @@ | ||||
|   <component name="SharedIndexes"> | ||||
|     <attachedChunks> | ||||
|       <set> | ||||
|         <option value="bundled-gosdk-5df93f7ad4aa-df9ad98b711f-org.jetbrains.plugins.go.sharedIndexes.bundled-GO-242.21829.220" /> | ||||
|         <option value="bundled-js-predefined-d6986cc7102b-7c0b70fcd90d-JavaScript-GO-242.21829.220" /> | ||||
|         <option value="bundled-gosdk-5df93f7ad4aa-df9ad98b711f-org.jetbrains.plugins.go.sharedIndexes.bundled-GO-242.23339.24" /> | ||||
|         <option value="bundled-js-predefined-d6986cc7102b-5c90d61e3bab-JavaScript-GO-242.23339.24" /> | ||||
|       </set> | ||||
|     </attachedChunks> | ||||
|   </component> | ||||
|   | ||||
| @@ -10,7 +10,7 @@ FROM golang:alpine | ||||
|  | ||||
| COPY --from=paperclip-server /dist /paperclip/server | ||||
|  | ||||
| RUN apk add --no-cache ffmpeg | ||||
| RUN apk add --no-cache ffmpeg exiftool | ||||
|  | ||||
| EXPOSE 8445 | ||||
|  | ||||
|   | ||||
							
								
								
									
										1
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								go.mod
									
									
									
									
									
								
							| @@ -30,6 +30,7 @@ require ( | ||||
| require ( | ||||
| 	github.com/andybalholm/brotli v1.1.0 // indirect | ||||
| 	github.com/armon/go-metrics v0.4.1 // indirect | ||||
| 	github.com/barasher/go-exiftool v1.10.0 // indirect | ||||
| 	github.com/beorn7/perks v1.0.1 // indirect | ||||
| 	github.com/cespare/xxhash/v2 v2.3.0 // indirect | ||||
| 	github.com/dustin/go-humanize v1.0.1 // indirect | ||||
|   | ||||
							
								
								
									
										2
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.sum
									
									
									
									
									
								
							| @@ -49,6 +49,8 @@ github.com/armon/go-metrics v0.4.1 h1:hR91U9KYmb6bLBYLQjyM+3j+rcd/UhE+G78SFnF8gJ | ||||
| github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+3JqfkOG4= | ||||
| github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= | ||||
| github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= | ||||
| github.com/barasher/go-exiftool v1.10.0 h1:f5JY5jc42M7tzR6tbL9508S2IXdIcG9QyieEXNMpIhs= | ||||
| github.com/barasher/go-exiftool v1.10.0/go.mod h1:F9s/a3uHSM8YniVfwF+sbQUtP8Gmh9nyzigNF+8vsWo= | ||||
| github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= | ||||
| github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= | ||||
| github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= | ||||
|   | ||||
| @@ -5,6 +5,7 @@ import ( | ||||
| 	"crypto/sha256" | ||||
| 	"encoding/hex" | ||||
| 	"fmt" | ||||
| 	"github.com/barasher/go-exiftool" | ||||
| 	"image" | ||||
| 	"io" | ||||
| 	"os" | ||||
| @@ -147,6 +148,22 @@ func AnalyzeAttachment(file models.Attachment) error { | ||||
| 				"height": height, | ||||
| 				"ratio":  ratio, | ||||
| 			} | ||||
|  | ||||
| 			// Removing location EXIF data | ||||
| 			et, err := exiftool.NewExiftool() | ||||
| 			if err != nil { | ||||
| 				return fmt.Errorf("error when intializing exiftool: %v", err) | ||||
| 			} | ||||
| 			defer et.Close() | ||||
| 			exif := et.ExtractMetadata(dst) | ||||
| 			for _, data := range exif { | ||||
| 				for k, _ := range data.Fields { | ||||
| 					if strings.HasPrefix(k, "GPS") { | ||||
| 						data.Clear(k) | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 			et.WriteMetadata(exif) | ||||
| 		case "video": | ||||
| 			// Dealing with video | ||||
| 			ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||||
| @@ -170,6 +187,22 @@ func AnalyzeAttachment(file models.Attachment) error { | ||||
| 				"color_range": stream.ColorRange, | ||||
| 				"color_space": stream.ColorSpace, | ||||
| 			} | ||||
|  | ||||
| 			// Removing location EXIF data | ||||
| 			et, err := exiftool.NewExiftool() | ||||
| 			if err != nil { | ||||
| 				return fmt.Errorf("error when intializing exiftool: %v", err) | ||||
| 			} | ||||
| 			defer et.Close() | ||||
| 			exif := et.ExtractMetadata(dst) | ||||
| 			for _, data := range exif { | ||||
| 				for k, _ := range data.Fields { | ||||
| 					if strings.HasPrefix(k, "GPS") { | ||||
| 						data.Clear(k) | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 			et.WriteMetadata(exif) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user