How to use sanitize method of main Package

Best Mock code snippet using main.sanitize

sanitize_test.go

Source:sanitize_test.go Github

copy

Full Screen

1package heartbeat_test2import (3 "regexp"4 "testing"5 "github.com/wakatime/wakatime-cli/pkg/heartbeat"6 "github.com/wakatime/wakatime-cli/pkg/regex"7 "github.com/stretchr/testify/assert"8 "github.com/stretchr/testify/require"9)10func TestWithSanitization_ObfuscateFile(t *testing.T) {11 opt := heartbeat.WithSanitization(heartbeat.SanitizeConfig{12 FilePatterns: []regex.Regex{regexp.MustCompile(".*")},13 })14 handle := opt(func(hh []heartbeat.Heartbeat) ([]heartbeat.Result, error) {15 assert.Equal(t, []heartbeat.Heartbeat{16 {17 Category: heartbeat.CodingCategory,18 Entity: "HIDDEN.go",19 EntityType: heartbeat.FileType,20 IsWrite: heartbeat.PointerTo(true),21 Language: heartbeat.PointerTo("Go"),22 Project: heartbeat.PointerTo("wakatime"),23 Time: 1585598060,24 UserAgent: "wakatime/13.0.7",25 },26 }, hh)27 return []heartbeat.Result{28 {29 Status: 201,30 },31 }, nil32 })33 result, err := handle([]heartbeat.Heartbeat{testHeartbeat()})34 require.NoError(t, err)35 assert.Equal(t, []heartbeat.Result{36 {37 Status: 201,38 },39 }, result)40}41func TestSanitize_Obfuscate(t *testing.T) {42 tests := map[string]struct {43 Heartbeat heartbeat.Heartbeat44 Expected heartbeat.Heartbeat45 }{46 "file": {47 Heartbeat: heartbeat.Heartbeat{48 Branch: heartbeat.PointerTo("heartbeat"),49 Category: heartbeat.CodingCategory,50 CursorPosition: heartbeat.PointerTo(12),51 Dependencies: []string{"dep1", "dep2"},52 Entity: "/tmp/main.go",53 EntityType: heartbeat.FileType,54 IsWrite: heartbeat.PointerTo(true),55 Language: heartbeat.PointerTo("Go"),56 LineNumber: heartbeat.PointerTo(42),57 Lines: heartbeat.PointerTo(100),58 Project: heartbeat.PointerTo("wakatime"),59 Time: 1585598060,60 UserAgent: "wakatime/13.0.7",61 },62 Expected: heartbeat.Heartbeat{63 Category: heartbeat.CodingCategory,64 Entity: "HIDDEN.go",65 EntityType: heartbeat.FileType,66 IsWrite: heartbeat.PointerTo(true),67 Language: heartbeat.PointerTo("Go"),68 Project: heartbeat.PointerTo("wakatime"),69 Time: 1585598060,70 UserAgent: "wakatime/13.0.7",71 },72 },73 "app": {74 Heartbeat: heartbeat.Heartbeat{75 Category: heartbeat.CodingCategory,76 Entity: "Slack",77 EntityType: heartbeat.AppType,78 Time: 1585598060,79 UserAgent: "wakatime/13.0.7",80 },81 Expected: heartbeat.Heartbeat{82 Category: heartbeat.CodingCategory,83 Entity: "HIDDEN",84 EntityType: heartbeat.AppType,85 Time: 1585598060,86 UserAgent: "wakatime/13.0.7",87 },88 },89 "domain": {90 Heartbeat: heartbeat.Heartbeat{91 Category: heartbeat.BrowsingCategory,92 Entity: "wakatime.com",93 EntityType: heartbeat.DomainType,94 Time: 1585598060,95 UserAgent: "wakatime/13.0.7",96 },97 Expected: heartbeat.Heartbeat{98 Category: heartbeat.BrowsingCategory,99 Entity: "HIDDEN",100 EntityType: heartbeat.DomainType,101 Time: 1585598060,102 UserAgent: "wakatime/13.0.7",103 },104 },105 }106 for name, test := range tests {107 t.Run(name, func(t *testing.T) {108 r := heartbeat.Sanitize(test.Heartbeat, heartbeat.SanitizeConfig{109 FilePatterns: []regex.Regex{regexp.MustCompile(".*")},110 })111 assert.Equal(t, test.Expected, r)112 })113 }114}115func TestSanitize_ObfuscateFile_SkipBranchIfNotMatching(t *testing.T) {116 r := heartbeat.Sanitize(testHeartbeat(), heartbeat.SanitizeConfig{117 FilePatterns: []regex.Regex{regexp.MustCompile(".*")},118 BranchPatterns: []regex.Regex{regexp.MustCompile("not_matching")},119 })120 assert.Equal(t, heartbeat.Heartbeat{121 Branch: heartbeat.PointerTo("heartbeat"),122 Category: heartbeat.CodingCategory,123 Entity: "HIDDEN.go",124 EntityType: heartbeat.FileType,125 IsWrite: heartbeat.PointerTo(true),126 Language: heartbeat.PointerTo("Go"),127 Project: heartbeat.PointerTo("wakatime"),128 Time: 1585598060,129 UserAgent: "wakatime/13.0.7",130 }, r)131}132func TestSanitize_ObfuscateFile_NilFields(t *testing.T) {133 h := testHeartbeat()134 h.Branch = nil135 r := heartbeat.Sanitize(h, heartbeat.SanitizeConfig{136 FilePatterns: []regex.Regex{regexp.MustCompile(".*")},137 BranchPatterns: []regex.Regex{regexp.MustCompile(".*")},138 })139 assert.Equal(t, heartbeat.Heartbeat{140 Category: heartbeat.CodingCategory,141 Entity: "HIDDEN.go",142 EntityType: heartbeat.FileType,143 IsWrite: heartbeat.PointerTo(true),144 Language: heartbeat.PointerTo("Go"),145 Project: heartbeat.PointerTo("wakatime"),146 Time: 1585598060,147 UserAgent: "wakatime/13.0.7",148 }, r)149}150func TestSanitize_ObfuscateProject(t *testing.T) {151 r := heartbeat.Sanitize(testHeartbeat(), heartbeat.SanitizeConfig{152 ProjectPatterns: []regex.Regex{regexp.MustCompile(".*")},153 })154 assert.Equal(t, heartbeat.Heartbeat{155 Category: heartbeat.CodingCategory,156 Entity: "/tmp/main.go",157 EntityType: heartbeat.FileType,158 IsWrite: heartbeat.PointerTo(true),159 Language: heartbeat.PointerTo("Go"),160 Project: heartbeat.PointerTo("wakatime"),161 Time: 1585598060,162 UserAgent: "wakatime/13.0.7",163 }, r)164}165func TestSanitize_ObfuscateProject_SkipBranchIfNotMatching(t *testing.T) {166 r := heartbeat.Sanitize(testHeartbeat(), heartbeat.SanitizeConfig{167 ProjectPatterns: []regex.Regex{regexp.MustCompile(".*")},168 BranchPatterns: []regex.Regex{regexp.MustCompile("not_matching")},169 })170 assert.Equal(t, heartbeat.Heartbeat{171 Branch: heartbeat.PointerTo("heartbeat"),172 Category: heartbeat.CodingCategory,173 Entity: "/tmp/main.go",174 EntityType: heartbeat.FileType,175 IsWrite: heartbeat.PointerTo(true),176 Language: heartbeat.PointerTo("Go"),177 Project: heartbeat.PointerTo("wakatime"),178 Time: 1585598060,179 UserAgent: "wakatime/13.0.7",180 }, r)181}182func TestSanitize_ObfuscateProject_NilFields(t *testing.T) {183 h := testHeartbeat()184 h.Branch = nil185 r := heartbeat.Sanitize(h, heartbeat.SanitizeConfig{186 ProjectPatterns: []regex.Regex{regexp.MustCompile(".*")},187 BranchPatterns: []regex.Regex{regexp.MustCompile(".*")},188 })189 assert.Equal(t, heartbeat.Heartbeat{190 Category: heartbeat.CodingCategory,191 Entity: "/tmp/main.go",192 EntityType: heartbeat.FileType,193 IsWrite: heartbeat.PointerTo(true),194 Language: heartbeat.PointerTo("Go"),195 Project: heartbeat.PointerTo("wakatime"),196 Time: 1585598060,197 UserAgent: "wakatime/13.0.7",198 }, r)199}200func TestSanitize_ObfuscateBranch(t *testing.T) {201 r := heartbeat.Sanitize(testHeartbeat(), heartbeat.SanitizeConfig{202 BranchPatterns: []regex.Regex{regexp.MustCompile(".*")},203 })204 assert.Equal(t, heartbeat.Heartbeat{205 Category: heartbeat.CodingCategory,206 CursorPosition: heartbeat.PointerTo(12),207 Dependencies: []string{"dep1", "dep2"},208 Entity: "/tmp/main.go",209 EntityType: heartbeat.FileType,210 IsWrite: heartbeat.PointerTo(true),211 Language: heartbeat.PointerTo("Go"),212 LineNumber: heartbeat.PointerTo(42),213 Lines: heartbeat.PointerTo(100),214 Project: heartbeat.PointerTo("wakatime"),215 Time: 1585598060,216 UserAgent: "wakatime/13.0.7",217 }, r)218}219func TestSanitize_ObfuscateBranch_NilFields(t *testing.T) {220 h := testHeartbeat()221 h.Branch = nil222 h.Project = nil223 r := heartbeat.Sanitize(h, heartbeat.SanitizeConfig{224 BranchPatterns: []regex.Regex{regexp.MustCompile(".*")},225 })226 assert.Equal(t, heartbeat.Heartbeat{227 Category: heartbeat.CodingCategory,228 CursorPosition: heartbeat.PointerTo(12),229 Dependencies: []string{"dep1", "dep2"},230 Entity: "/tmp/main.go",231 EntityType: heartbeat.FileType,232 IsWrite: heartbeat.PointerTo(true),233 Language: heartbeat.PointerTo("Go"),234 LineNumber: heartbeat.PointerTo(42),235 Lines: heartbeat.PointerTo(100),236 Time: 1585598060,237 UserAgent: "wakatime/13.0.7",238 }, r)239}240func TestSanitize_EmptyConfigDoNothing(t *testing.T) {241 r := heartbeat.Sanitize(testHeartbeat(), heartbeat.SanitizeConfig{})242 assert.Equal(t, heartbeat.Heartbeat{243 Branch: heartbeat.PointerTo("heartbeat"),244 Category: heartbeat.CodingCategory,245 CursorPosition: heartbeat.PointerTo(12),246 Dependencies: []string{"dep1", "dep2"},247 Entity: "/tmp/main.go",248 EntityType: heartbeat.FileType,249 IsWrite: heartbeat.PointerTo(true),250 Language: heartbeat.PointerTo("Go"),251 LineNumber: heartbeat.PointerTo(42),252 Lines: heartbeat.PointerTo(100),253 Project: heartbeat.PointerTo("wakatime"),254 Time: 1585598060,255 UserAgent: "wakatime/13.0.7",256 }, r)257}258func TestSanitize_EmptyConfigDoNothing_EmptyDependencies(t *testing.T) {259 h := testHeartbeat()260 h.Dependencies = []string{}261 r := heartbeat.Sanitize(h, heartbeat.SanitizeConfig{})262 assert.Equal(t, heartbeat.Heartbeat{263 Branch: heartbeat.PointerTo("heartbeat"),264 Category: heartbeat.CodingCategory,265 CursorPosition: heartbeat.PointerTo(12),266 Entity: "/tmp/main.go",267 EntityType: heartbeat.FileType,268 IsWrite: heartbeat.PointerTo(true),269 Language: heartbeat.PointerTo("Go"),270 LineNumber: heartbeat.PointerTo(42),271 Lines: heartbeat.PointerTo(100),272 Project: heartbeat.PointerTo("wakatime"),273 Time: 1585598060,274 UserAgent: "wakatime/13.0.7",275 }, r)276}277func TestSanitize_ObfuscateProjectFolder(t *testing.T) {278 h := testHeartbeat()279 h.Entity = "/path/to/project/main.go"280 h.ProjectPath = "/path/to"281 r := heartbeat.Sanitize(h, heartbeat.SanitizeConfig{282 HideProjectFolder: true,283 })284 assert.Equal(t, heartbeat.Heartbeat{285 Branch: heartbeat.PointerTo("heartbeat"),286 Category: heartbeat.CodingCategory,287 CursorPosition: heartbeat.PointerTo(12),288 Dependencies: []string{"dep1", "dep2"},289 Entity: "project/main.go",290 EntityType: heartbeat.FileType,291 IsWrite: heartbeat.PointerTo(true),292 Language: heartbeat.PointerTo("Go"),293 LineNumber: heartbeat.PointerTo(42),294 Lines: heartbeat.PointerTo(100),295 Project: heartbeat.PointerTo("wakatime"),296 ProjectPath: "/path/to/",297 Time: 1585598060,298 UserAgent: "wakatime/13.0.7",299 }, r)300}301func TestSanitize_ObfuscateProjectFolder_Override(t *testing.T) {302 h := testHeartbeat()303 h.Entity = "/path/to/project/main.go"304 h.ProjectPath = "/original/folder"305 h.ProjectPathOverride = "/path/to"306 r := heartbeat.Sanitize(h, heartbeat.SanitizeConfig{307 HideProjectFolder: true,308 })309 assert.Equal(t, heartbeat.Heartbeat{310 Branch: heartbeat.PointerTo("heartbeat"),311 Category: heartbeat.CodingCategory,312 CursorPosition: heartbeat.PointerTo(12),313 Dependencies: []string{"dep1", "dep2"},314 Entity: "project/main.go",315 EntityType: heartbeat.FileType,316 IsWrite: heartbeat.PointerTo(true),317 Language: heartbeat.PointerTo("Go"),318 LineNumber: heartbeat.PointerTo(42),319 Lines: heartbeat.PointerTo(100),320 Project: heartbeat.PointerTo("wakatime"),321 ProjectPath: "/original/folder/",322 ProjectPathOverride: "/path/to/",323 Time: 1585598060,324 UserAgent: "wakatime/13.0.7",325 }, r)326}327func TestSanitize_ObfuscateCredentials_RemoteFile(t *testing.T) {328 h := testHeartbeat()329 h.Entity = "ssh://wakatime:1234@192.168.1.1/path/to/remote/main.go"330 r := heartbeat.Sanitize(h, heartbeat.SanitizeConfig{331 RemoteAddressPattern: regexp.MustCompile(`(?i)^((ssh|sftp)://)+(?P<credentials>[^:@]+(:([^:@])+)?@)?[^:]+(:\d+)?`),332 })333 assert.Equal(t, heartbeat.Heartbeat{334 Branch: heartbeat.PointerTo("heartbeat"),335 Category: heartbeat.CodingCategory,336 CursorPosition: heartbeat.PointerTo(12),337 Dependencies: []string{"dep1", "dep2"},338 Entity: "ssh://192.168.1.1/path/to/remote/main.go",339 EntityType: heartbeat.FileType,340 IsWrite: heartbeat.PointerTo(true),341 Language: heartbeat.PointerTo("Go"),342 LineNumber: heartbeat.PointerTo(42),343 Lines: heartbeat.PointerTo(100),344 Project: heartbeat.PointerTo("wakatime"),345 Time: 1585598060,346 UserAgent: "wakatime/13.0.7",347 }, r)348}349func TestShouldSanitize(t *testing.T) {350 tests := map[string]struct {351 Subject string352 Regex []regex.Regex353 Expected bool354 }{355 "match_single": {356 Subject: "fix.123",357 Regex: []regex.Regex{358 regexp.MustCompile("fix.*"),359 },360 Expected: true,361 },362 "match_multiple": {363 Subject: "fix.456",364 Regex: []regex.Regex{365 regexp.MustCompile("bar.*"),366 regexp.MustCompile("fix.*"),367 },368 Expected: true,369 },370 "not_match": {371 Subject: "foo",372 Regex: []regex.Regex{373 regexp.MustCompile("bar.*"),374 regexp.MustCompile("fix.*"),375 },376 Expected: false,377 },378 }379 for name, test := range tests {380 t.Run(name, func(t *testing.T) {381 shouldSanitize := heartbeat.ShouldSanitize(test.Subject, test.Regex)382 assert.Equal(t, test.Expected, shouldSanitize)383 })384 }385}386func testHeartbeat() heartbeat.Heartbeat {387 return heartbeat.Heartbeat{388 Branch: heartbeat.PointerTo("heartbeat"),389 Category: heartbeat.CodingCategory,390 CursorPosition: heartbeat.PointerTo(12),391 Dependencies: []string{"dep1", "dep2"},392 Entity: "/tmp/main.go",393 EntityType: heartbeat.FileType,394 IsWrite: heartbeat.PointerTo(true),395 Language: heartbeat.PointerTo("Go"),396 LineNumber: heartbeat.PointerTo(42),397 Lines: heartbeat.PointerTo(100),398 Project: heartbeat.PointerTo("wakatime"),399 Time: 1585598060,400 UserAgent: "wakatime/13.0.7",401 }402}...

Full Screen

Full Screen

import_worker.go

Source:import_worker.go Github

copy

Full Screen

...5 "github.com/photoprism/photoprism/internal/query"6 "github.com/photoprism/photoprism/internal/entity"7 "github.com/photoprism/photoprism/internal/event"8 "github.com/photoprism/photoprism/pkg/fs"9 "github.com/photoprism/photoprism/pkg/sanitize"10)11type ImportJob struct {12 FileName string13 Related RelatedFiles14 IndexOpt IndexOptions15 ImportOpt ImportOptions16 Imp *Import17}18func ImportWorker(jobs <-chan ImportJob) {19 for job := range jobs {20 var destMainFileName string21 related := job.Related22 imp := job.Imp23 opt := job.ImportOpt24 indexOpt := job.IndexOpt25 importPath := job.ImportOpt.Path26 if related.Main == nil {27 log.Warnf("import: %s belongs to no supported media file", sanitize.Log(fs.RelName(job.FileName, importPath)))28 continue29 }30 if related.Main.NeedsExifToolJson() {31 if jsonName, err := imp.convert.ToJson(related.Main); err != nil {32 log.Debugf("import: %s in %s (extract metadata)", sanitize.Log(err.Error()), sanitize.Log(related.Main.BaseName()))33 } else if err := related.Main.ReadExifToolJson(); err != nil {34 log.Errorf("import: %s in %s (read metadata)", sanitize.Log(err.Error()), sanitize.Log(related.Main.BaseName()))35 } else {36 log.Debugf("import: created %s", filepath.Base(jsonName))37 }38 }39 originalName := related.Main.RelName(importPath)40 event.Publish("import.file", event.Data{41 "fileName": originalName,42 "baseName": filepath.Base(related.Main.FileName()),43 })44 for _, f := range related.Files {45 relFileName := f.RelName(importPath)46 if destFileName, err := imp.DestinationFilename(related.Main, f); err == nil {47 destDir := filepath.Dir(destFileName)48 if fs.PathExists(destDir) {49 // Do nothing.50 } else if err := os.MkdirAll(destDir, os.ModePerm); err != nil {51 log.Errorf("import: failed creating folder for %s (%s)", sanitize.Log(f.BaseName()), err.Error())52 } else {53 destDirRel := fs.RelName(destDir, imp.originalsPath())54 folder := entity.NewFolder(entity.RootOriginals, destDirRel, fs.BirthTime(destDir))55 if err := folder.Create(); err == nil {56 log.Infof("import: created folder /%s", folder.Path)57 }58 }59 if related.Main.HasSameName(f) {60 destMainFileName = destFileName61 log.Infof("import: moving main %s file %s to %s", f.FileType(), sanitize.Log(relFileName), sanitize.Log(fs.RelName(destFileName, imp.originalsPath())))62 } else {63 log.Infof("import: moving related %s file %s to %s", f.FileType(), sanitize.Log(relFileName), sanitize.Log(fs.RelName(destFileName, imp.originalsPath())))64 }65 if opt.Move {66 if err := f.Move(destFileName); err != nil {67 logRelName := sanitize.Log(fs.RelName(destMainFileName, imp.originalsPath()))68 log.Debugf("import: %s", err.Error())69 log.Warnf("import: failed moving file to %s, is another import running at the same time?", logRelName)70 }71 } else {72 if err := f.Copy(destFileName); err != nil {73 logRelName := sanitize.Log(fs.RelName(destMainFileName, imp.originalsPath()))74 log.Debugf("import: %s", err.Error())75 log.Warnf("import: failed copying file to %s, is another import running at the same time?", logRelName)76 }77 }78 } else {79 log.Infof("import: %s", err)80 // Try to add duplicates to selected album(s) as well, see #991.81 if fileHash := f.Hash(); fileHash == "" {82 // Do nothing.83 } else if file, err := entity.FirstFileByHash(fileHash); err != nil {84 // Do nothing.85 } else if err := entity.AddPhotoToAlbums(file.PhotoUID, opt.Albums); err != nil {86 log.Warn(err)87 }88 // Remove duplicates to save storage.89 if opt.RemoveExistingFiles {90 if err := f.Remove(); err != nil {91 log.Errorf("import: failed deleting %s (%s)", sanitize.Log(f.BaseName()), err.Error())92 } else {93 log.Infof("import: deleted %s (already exists)", sanitize.Log(relFileName))94 }95 }96 }97 }98 if destMainFileName != "" {99 f, err := NewMediaFile(destMainFileName)100 if err != nil {101 log.Errorf("import: %s in %s", err.Error(), sanitize.Log(fs.RelName(destMainFileName, imp.originalsPath())))102 continue103 }104 if f.NeedsExifToolJson() {105 if jsonName, err := imp.convert.ToJson(f); err != nil {106 log.Debugf("import: %s in %s (extract metadata)", sanitize.Log(err.Error()), sanitize.Log(f.BaseName()))107 } else {108 log.Debugf("import: created %s", filepath.Base(jsonName))109 }110 }111 if indexOpt.Convert && f.IsMedia() && !f.HasJpeg() {112 if jpegFile, err := imp.convert.ToJpeg(f); err != nil {113 log.Errorf("import: %s in %s (convert to jpeg)", err.Error(), sanitize.Log(fs.RelName(destMainFileName, imp.originalsPath())))114 continue115 } else {116 log.Debugf("import: created %s", sanitize.Log(jpegFile.BaseName()))117 }118 }119 if jpg, err := f.Jpeg(); err != nil {120 log.Error(err)121 } else {122 if err := jpg.ResampleDefault(imp.thumbPath(), false); err != nil {123 log.Errorf("import: %s in %s (resample)", err.Error(), sanitize.Log(jpg.BaseName()))124 continue125 }126 }127 related, err := f.RelatedFiles(imp.conf.Settings().StackSequences())128 if err != nil {129 log.Errorf("import: %s in %s (find related files)", err.Error(), sanitize.Log(fs.RelName(destMainFileName, imp.originalsPath())))130 continue131 }132 done := make(map[string]bool)133 ind := imp.index134 sizeLimit := ind.conf.OriginalsLimit()135 if related.Main != nil {136 f := related.Main137 // Enforce file size limit for originals.138 if sizeLimit > 0 && f.FileSize() > sizeLimit {139 log.Warnf("import: %s exceeds file size limit (%d / %d MB)", sanitize.Log(f.BaseName()), f.FileSize()/(1024*1024), sizeLimit/(1024*1024))140 continue141 }142 res := ind.MediaFile(f, indexOpt, originalName)143 log.Infof("import: %s main %s file %s", res, f.FileType(), sanitize.Log(f.RelName(ind.originalsPath())))144 done[f.FileName()] = true145 if res.Success() {146 if err := entity.AddPhotoToAlbums(res.PhotoUID, opt.Albums); err != nil {147 log.Warn(err)148 }149 } else {150 continue151 }152 } else {153 log.Warnf("import: found no main file for %s, conversion to jpeg may have failed", fs.RelName(destMainFileName, imp.originalsPath()))154 }155 for _, f := range related.Files {156 if f == nil {157 continue158 }159 if done[f.FileName()] {160 continue161 }162 done[f.FileName()] = true163 // Enforce file size limit for originals.164 if sizeLimit > 0 && f.FileSize() > sizeLimit {165 log.Warnf("import: %s exceeds file size limit (%d / %d MB)", sanitize.Log(f.BaseName()), f.FileSize()/(1024*1024), sizeLimit/(1024*1024))166 continue167 }168 if f.NeedsExifToolJson() {169 if jsonName, err := imp.convert.ToJson(f); err != nil {170 log.Debugf("import: %s in %s (extract metadata)", sanitize.Log(err.Error()), sanitize.Log(f.BaseName()))171 } else {172 log.Debugf("import: created %s", filepath.Base(jsonName))173 }174 }175 res := ind.MediaFile(f, indexOpt, "")176 if res.Indexed() && f.IsJpeg() {177 if err := f.ResampleDefault(ind.thumbPath(), false); err != nil {178 log.Errorf("import: failed creating thumbnails for %s (%s)", sanitize.Log(f.BaseName()), err.Error())179 query.SetFileError(res.FileUID, err.Error())180 }181 }182 log.Infof("import: %s related %s file %s", res, f.FileType(), sanitize.Log(f.RelName(ind.originalsPath())))183 }184 }185 }186}...

Full Screen

Full Screen

index_main.go

Source:index_main.go Github

copy

Full Screen

2import (3 "fmt"4 "path/filepath"5 "github.com/photoprism/photoprism/internal/query"6 "github.com/photoprism/photoprism/pkg/sanitize"7)8// IndexMain indexes the main file from a group of related files and returns the result.9func IndexMain(related *RelatedFiles, ind *Index, o IndexOptions) (result IndexResult) {10 // Skip if main file is nil.11 if related.Main == nil {12 result.Err = fmt.Errorf("index: no main file for %s", sanitize.Log(related.String()))13 result.Status = IndexFailed14 return result15 }16 f := related.Main17 // Enforce file size and resolution limits.18 if exceeds, actual := f.ExceedsFileSize(o.OriginalsLimit); exceeds {19 result.Err = fmt.Errorf("index: %s exceeds file size limit (%d / %d MB)", sanitize.Log(f.RootRelName()), actual, o.OriginalsLimit)20 result.Status = IndexFailed21 return result22 } else if exceeds, actual = f.ExceedsResolution(o.ResolutionLimit); exceeds {23 result.Err = fmt.Errorf("index: %s exceeds resolution limit (%d / %d MP)", sanitize.Log(f.RootRelName()), actual, o.ResolutionLimit)24 result.Status = IndexFailed25 return result26 }27 // Extract metadata to a JSON file with Exiftool.28 if f.NeedsExifToolJson() {29 if jsonName, err := ind.convert.ToJson(f); err != nil {30 log.Debugf("index: %s in %s (extract metadata)", sanitize.Log(err.Error()), sanitize.Log(f.RootRelName()))31 } else {32 log.Debugf("index: created %s", filepath.Base(jsonName))33 }34 }35 // Create JPEG sidecar for media files in other formats so that thumbnails can be created.36 if o.Convert && f.IsMedia() && !f.HasJpeg() {37 if jpg, err := ind.convert.ToJpeg(f, false); err != nil {38 result.Err = fmt.Errorf("index: failed converting %s to jpeg (%s)", sanitize.Log(f.RootRelName()), err.Error())39 result.Status = IndexFailed40 return result41 } else if exceeds, actual := jpg.ExceedsResolution(o.ResolutionLimit); exceeds {42 result.Err = fmt.Errorf("index: %s exceeds resolution limit (%d / %d MP)", sanitize.Log(f.RootRelName()), actual, o.ResolutionLimit)43 result.Status = IndexFailed44 return result45 } else {46 log.Debugf("index: created %s", sanitize.Log(jpg.BaseName()))47 if err := jpg.CreateThumbnails(ind.thumbPath(), false); err != nil {48 result.Err = fmt.Errorf("index: failed creating thumbnails for %s (%s)", sanitize.Log(f.RootRelName()), err.Error())49 result.Status = IndexFailed50 return result51 }52 related.Files = append(related.Files, jpg)53 }54 }55 // Index main MediaFile.56 exists := ind.files.Exists(f.RootRelName(), f.Root())57 result = ind.MediaFile(f, o, "", "")58 // Save file error.59 if fileUid, err := result.FileError(); err != nil {60 query.SetFileError(fileUid, err.Error())61 }62 // Log index result.63 if result.Failed() {64 log.Error(result.Err)65 if exists {66 log.Errorf("index: %s updating main %s file %s", result, f.FileType(), sanitize.Log(f.RootRelName()))67 } else {68 log.Errorf("index: %s adding main %s file %s", result, f.FileType(), sanitize.Log(f.RootRelName()))69 }70 } else {71 log.Infof("index: %s main %s file %s", result, f.FileType(), sanitize.Log(f.RootRelName()))72 }73 return result74}...

Full Screen

Full Screen

sanitize

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println(sanitize("Hello World"))4}5import "fmt"6func main() {7 fmt.Println(sanitize("Hello World"))8}9import "fmt"10func main() {11 fmt.Println(sanitize("Hello World"))12}13import "fmt"14func main() {15 fmt.Println(sanitize("Hello World"))16}17import "fmt"18func main() {19 fmt.Println(sanitize("Hello World"))20}21import "fmt"22func main() {23 fmt.Println(sanitize("Hello World"))24}25import "fmt"26func main() {27 fmt.Println(sanitize("Hello World"))28}29import "fmt"30func main() {31 fmt.Println(sanitize("Hello World"))32}33import "fmt"34func main() {35 fmt.Println(sanitize("Hello World"))36}37import "fmt"38func main() {39 fmt.Println(sanitize("Hello World"))40}41import "fmt"42func main() {43 fmt.Println(sanitize("Hello World"))44}45import "fmt"46func main() {47 fmt.Println(sanitize("Hello World"))48}49import "fmt"50func main() {51 fmt.Println(sanitize("Hello World"))52}53import

Full Screen

Full Screen

sanitize

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println(sanitize("Hello, playground"))4}5import "fmt"6func main() {7 fmt.Println(sanitize("Hello, playground"))8}9import "fmt"10func main() {11 fmt.Println(sanitize("Hello, playground"))12}13import "fmt"14func main() {15 fmt.Println(sanitize("Hello, playground"))16}17import "fmt"18func main() {19 fmt.Println(sanitize("Hello, playground"))20}21import (22func main() {23 files, err := filepath.Glob("*.go")24 if err != nil {25 fmt.Println(err)26 os.Exit(1)27 }28 for _, file := range files {29 fmt.Println(file)30 }31}

Full Screen

Full Screen

sanitize

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(sanitize("this is a test"))4}5import (6func main() {7 fmt.Println(sanitize("this is a test"))8}9import (10func main() {11 fmt.Println(sanitize("this is a test"))12}13import (14func main() {15 fmt.Println(sanitize("this is a test"))16}17import (18func main() {19 fmt.Println(sanitize("this is a test"))20}21import (22func main() {23 fmt.Println(sanitize("this is a test"))24}25import (26func main() {27 fmt.Println(sanitize("this is a test"))28}29import (30func main() {31 fmt.Println(sanitize("this is a test"))32}33import (34func main() {35 fmt.Println(sanitize("this is a test"))36}37import (38func main() {39 fmt.Println(sanitize("this is a test"))40}41import (42func main() {43 fmt.Println(sanitize("this is a test"))44}45import (46func main() {47 fmt.Println(sanitize("this is a test"))48}49import (

Full Screen

Full Screen

sanitize

Using AI Code Generation

copy

Full Screen

1import "fmt"2import "sanitizer"3func main() {4 fmt.Println(sanitizer.Sanitize("Hello, playground"))5}6import "fmt"7import "sanitizer"8func main() {9 fmt.Println(sanitizer.Sanitize("Hello, playground"))10}11func Sanitize(input string) string {12}13 /usr/local/go/src/sanitizer (from $GOROOT)14 /Users/username/code/go/src/sanitizer (from $GOPATH)

Full Screen

Full Screen

sanitize

Using AI Code Generation

copy

Full Screen

1import (2type main struct {3}4func (m main) sanitize() {5}6func main() {7 m := main{name: "Jack", age: 20}8 fmt.Println(m.name, m.age)9 m.sanitize()10 fmt.Println(m.name, m.age)11}12import (13type main struct {14}15func (m *main) sanitize() {16}17func main() {18 m := main{name: "Jack", age: 20}19 fmt.Println(m.name, m.age)20 m.sanitize()21 fmt.Println(m.name, m.age)22}23import (24type main struct {25}26func (m *main) sanitize() {27}28func main() {29 m := main{name: "Jack", age: 20}30 fmt.Println(m.name, m.age)31 m.sanitize()32 fmt.Println(m.name, m.age)33 (&m).sanitize()34 fmt.Println(m.name, m.age)35}

Full Screen

Full Screen

sanitize

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(sanitize.Sanitize("This is a test"))4}5import (6func main() {7 fmt.Println(sanitize.Sanitize("This is a test"))8}9import (10func main() {11 fmt.Println(sanitize.Sanitize("This is a test"))12}13import (14func main() {15 fmt.Println(sanitize.Sanitize("This is a test"))16}17import (18func main() {19 fmt.Println(sanitize.Sanitize("This is a test"))20}21import (22func main() {23 fmt.Println(sanitize.Sanitize("This is a test"))24}25import (26func main() {27 fmt.Println(sanitize.Sanitize("This is a test"))28}29import (30func main() {31 fmt.Println(sanitize.Sanitize("This is a test"))32}33import (34func main() {35 fmt.Println(sanitize.Sanitize("This is a test"))36}37import (38func main() {39 fmt.Println(sanitize.Sanitize("This is a test"))40}

Full Screen

Full Screen

sanitize

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, playground")4 Sanitize()5 Sanitize()6 Sanitize()7 Sanitize()8}9import "fmt"10func Sanitize() {11 fmt.Println("Sanitize")12}13import "fmt"14func Sanitize() {15 fmt.Println("Sanitize")16}

Full Screen

Full Screen

sanitize

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(main.Sanitize("Hello!"))4}5import (6func Sanitize(s string) string {7 return strings.ToLower(s)8}9The package name is used to identify the package when you import it into another file. For example, if you have a package called sanitize , you can import it into another file like this:10import (11sanitize.Sanitize("Hello!")12You can import multiple packages into the same file. For example, if you want to use the strings package and the sanitize package, you can import them like this:13import (14sanitize.Sanitize(strings.ToLower("Hello!"))15You can also import packages from the standard library. For example, if you want to use the fmt package, you can import it like this:16import (17fmt.Println("Hello!")18You can import packages from the standard library, third-party packages, or your own packages. For example, if you want to use the sanitize package, you can import it like this:19import (

Full Screen

Full Screen

sanitize

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(sanitization.Sanitize("a < b"))4}5import (6func main() {7 fmt.Println(sanitization.Sanitize("a > b"))8}9import (10func main() {11 fmt.Println(sanitization.Sanitize("a <= b"))12}13import (14func main() {15 fmt.Println(sanitization.Sanitize("a >= b"))16}17import (18func main() {19 fmt.Println(sanitization.Sanitize("a == b"))20}21import (22func main() {23 fmt.Println(sanitization.Sanitize("a != b"))24}25import (26func main() {27 fmt.Println(sanitization.Sanitize("a && b"))28}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful