Skip to content

Commit

Permalink
Backend: Rename /internal/remote package to /internal/service
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Mayer <michael@photoprism.app>
  • Loading branch information
lastzero committed Jul 2, 2024
1 parent 08e1061 commit c096382
Show file tree
Hide file tree
Showing 50 changed files with 103 additions and 105 deletions.
4 changes: 2 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import (
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/mutex"
"github.com/photoprism/photoprism/internal/remote/hub"
"github.com/photoprism/photoprism/internal/remote/hub/places"
"github.com/photoprism/photoprism/internal/service/hub"
"github.com/photoprism/photoprism/internal/service/hub/places"
"github.com/photoprism/photoprism/internal/tensorflow/face"
"github.com/photoprism/photoprism/internal/thumb"
"github.com/photoprism/photoprism/pkg/checksum"
Expand Down
2 changes: 1 addition & 1 deletion internal/entity/album.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/remote/maps"
"github.com/photoprism/photoprism/internal/service/maps"
"github.com/photoprism/photoprism/pkg/clean"
"github.com/photoprism/photoprism/pkg/rnd"
"github.com/photoprism/photoprism/pkg/sortby"
Expand Down
2 changes: 1 addition & 1 deletion internal/entity/cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/remote/maps"
"github.com/photoprism/photoprism/internal/service/maps"
"github.com/photoprism/photoprism/pkg/s2"
"github.com/photoprism/photoprism/pkg/txt"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/entity/country.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jinzhu/gorm"

"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/remote/maps"
"github.com/photoprism/photoprism/internal/service/maps"
"github.com/photoprism/photoprism/pkg/txt"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/entity/photo_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/dustin/go-humanize/english"

"github.com/photoprism/photoprism/internal/remote/maps"
"github.com/photoprism/photoprism/internal/service/maps"
"github.com/photoprism/photoprism/internal/tensorflow/classify"
"github.com/photoprism/photoprism/pkg/clean"
"github.com/photoprism/photoprism/pkg/geo"
Expand Down
2 changes: 1 addition & 1 deletion internal/entity/place.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sync"
"time"

"github.com/photoprism/photoprism/internal/remote/maps"
"github.com/photoprism/photoprism/internal/service/maps"
"github.com/photoprism/photoprism/pkg/clean"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/entity/query/moments.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/remote/maps"
"github.com/photoprism/photoprism/internal/service/maps"
"github.com/photoprism/photoprism/pkg/clean"
"github.com/photoprism/photoprism/pkg/txt"
)
Expand Down
8 changes: 4 additions & 4 deletions internal/entity/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/ulule/deepcopier"

"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/remote"
"github.com/photoprism/photoprism/internal/remote/webdav"
"github.com/photoprism/photoprism/internal/service"
"github.com/photoprism/photoprism/internal/service/webdav"
"github.com/photoprism/photoprism/pkg/fs"
"github.com/photoprism/photoprism/pkg/txt"
)
Expand Down Expand Up @@ -140,7 +140,7 @@ func (m *Service) SaveForm(form form.Service) error {
}

// TODO: Support for other remote services in addition to WebDAV.
if m.AccType != remote.ServiceWebDAV {
if m.AccType != service.WebDAV {
m.AccShare = false // Disable manual upload.
m.AccSync = false // Disable background sync.
}
Expand Down Expand Up @@ -192,7 +192,7 @@ func (m *Service) Delete() error {

// Directories returns a list of directories or albums in an account.
func (m *Service) Directories() (result fs.FileInfos, err error) {
if m.AccType == remote.ServiceWebDAV {
if m.AccType == service.WebDAV {
var client *webdav.Client
if client, err = webdav.NewClient(m.AccURL, m.AccUser, m.AccPass, webdav.Timeout(m.AccTimeout)); err != nil {
return result, err
Expand Down
4 changes: 2 additions & 2 deletions internal/form/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package form
import (
"github.com/ulule/deepcopier"

"github.com/photoprism/photoprism/internal/remote"
"github.com/photoprism/photoprism/internal/service"
)

// Service represents a remote service form for uploading, downloading or syncing media files.
Expand Down Expand Up @@ -40,7 +40,7 @@ func NewService(m interface{}) (f Service, err error) {

// Discovery performs automatic service discovery.
func (f *Service) Discovery() error {
acc, err := remote.Discover(f.AccURL, f.AccUser, f.AccPass)
acc, err := service.Discover(f.AccURL, f.AccUser, f.AccPass)

if err != nil {
return err
Expand Down
63 changes: 0 additions & 63 deletions internal/remote/heuristic.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package remote
package service

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package remote
package service

import (
"testing"
Expand Down
62 changes: 62 additions & 0 deletions internal/service/heuristic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package service

import (
"net/url"
"strings"
)

type Heuristic struct {
ServiceType string
Domains []string
Paths []string
Method string
}

var Heuristics = []Heuristic{
{Facebook, []string{"facebook.com", "www.facebook.com"}, []string{}, "GET"},
{Twitter, []string{"twitter.com"}, []string{}, "GET"},
{Flickr, []string{"flickr.com", "www.flickr.com"}, []string{}, "GET"},
{Instagram, []string{"instagram.com", "www.instagram.com"}, []string{}, "GET"},
{Telegram, []string{"web.telegram.org", "www.telegram.org", "telegram.org"}, []string{}, "GET"},
{WhatsApp, []string{"web.whatsapp.com", "www.whatsapp.com", "whatsapp.com"}, []string{}, "GET"},
{OneDrive, []string{"onedrive.live.com"}, []string{}, "GET"},
{GDrive, []string{"drive.google.com"}, []string{}, "GET"},
{GPhotos, []string{"photos.google.com"}, []string{}, "GET"},
{WebDAV, []string{}, []string{"/", "/webdav/", "/originals/", "/remote.php/dav/files/{user}/", "/remote.php/webdav/", "/dav/files/{user}/", "/servlet/webdav.infostore/"}, "PROPFIND"},
}

func (h Heuristic) MatchDomain(match string) bool {
if len(h.Domains) == 0 {
return true
}

for _, m := range h.Domains {
if m == match {
return true
}
}

return false
}

func (h Heuristic) Discover(rawUrl, user string) *url.URL {
u, err := url.Parse(rawUrl)

if err != nil {
return nil
}

if HttpOk(h.Method, u.String()) {
return u
}

for _, p := range h.Paths {
u.Path = strings.Replace(p, "{user}", user, -1)

if HttpOk(h.Method, u.String()) {
return u
}
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"gopkg.in/yaml.v2"

"github.com/photoprism/photoprism/internal/remote/hub/places"
"github.com/photoprism/photoprism/internal/service/hub/places"
"github.com/photoprism/photoprism/pkg/clean"
"github.com/photoprism/photoprism/pkg/fs"
"github.com/photoprism/photoprism/pkg/header"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"strings"

"github.com/photoprism/photoprism/internal/remote/hub/places"
"github.com/photoprism/photoprism/internal/service/hub/places"
"github.com/photoprism/photoprism/pkg/clean"
"github.com/photoprism/photoprism/pkg/s2"
"github.com/photoprism/photoprism/pkg/txt"
Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 12 additions & 13 deletions internal/remote/remote.go → internal/service/remote.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Package remote provides detection of remote services for file sharing and synchronization.
Package service provides detection of remote services for file sharing and synchronization.
Copyright (c) 2018 - 2024 PhotoPrism UG. All rights reserved.
Expand All @@ -22,25 +22,24 @@ want to support our work, or just want to say hello.
Additional information can be found in our Developer Guide:
<https://docs.photoprism.app/developer-guide/>
*/
package remote
package service

import (
"net/http"
"time"
)

const (
ServiceWebDAV = "webdav"
ServiceFacebook = "facebook"
ServiceTwitter = "twitter"
ServiceFlickr = "flickr"
ServiceInstagram = "instagram"
ServiceEyeEm = "eyeem"
ServiceTelegram = "telegram"
ServiceWhatsApp = "whatsapp"
ServiceGPhotos = "gphotos"
ServiceGDrive = "gdrive"
ServiceOneDrive = "onedrive"
WebDAV = "webdav"
Facebook = "facebook"
Twitter = "twitter"
Flickr = "flickr"
Instagram = "instagram"
Telegram = "telegram"
WhatsApp = "whatsapp"
GPhotos = "gphotos"
GDrive = "gdrive"
OneDrive = "onedrive"
)

func HttpOk(method, rawUrl string) bool {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions internal/workers/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/mutex"
"github.com/photoprism/photoprism/internal/photoprism"
"github.com/photoprism/photoprism/internal/remote"
"github.com/photoprism/photoprism/internal/remote/webdav"
"github.com/photoprism/photoprism/internal/service"
"github.com/photoprism/photoprism/internal/service/webdav"
"github.com/photoprism/photoprism/internal/thumb"
"github.com/photoprism/photoprism/pkg/clean"
"github.com/photoprism/photoprism/pkg/fs"
Expand Down Expand Up @@ -64,7 +64,7 @@ func (w *Share) Start() (err error) {
return nil
}

if a.AccType != remote.ServiceWebDAV {
if a.AccType != service.WebDAV {
continue
}

Expand Down Expand Up @@ -159,7 +159,7 @@ func (w *Share) Start() (err error) {
return nil
}

if a.AccType != remote.ServiceWebDAV {
if a.AccType != service.WebDAV {
continue
}

Expand Down
4 changes: 2 additions & 2 deletions internal/workers/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/mutex"
"github.com/photoprism/photoprism/internal/remote"
"github.com/photoprism/photoprism/internal/service"
)

// Sync represents a sync worker.
Expand Down Expand Up @@ -62,7 +62,7 @@ func (w *Sync) Start() (err error) {
accounts, err := search.Accounts(f)

for _, a := range accounts {
if a.AccType != remote.ServiceWebDAV {
if a.AccType != service.WebDAV {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion internal/workers/sync_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/photoprism/photoprism/internal/get"
"github.com/photoprism/photoprism/internal/mutex"
"github.com/photoprism/photoprism/internal/photoprism"
"github.com/photoprism/photoprism/internal/remote/webdav"
"github.com/photoprism/photoprism/internal/service/webdav"
"github.com/photoprism/photoprism/pkg/clean"
"github.com/photoprism/photoprism/pkg/fs"
)
Expand Down
6 changes: 3 additions & 3 deletions internal/workers/sync_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package workers
import (
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/mutex"
"github.com/photoprism/photoprism/internal/remote"
"github.com/photoprism/photoprism/internal/remote/webdav"
"github.com/photoprism/photoprism/internal/service"
"github.com/photoprism/photoprism/internal/service/webdav"
"github.com/photoprism/photoprism/pkg/media"
)

// Updates the local list of remote files so that they can be downloaded in batches
func (w *Sync) refresh(a entity.Service) (complete bool, err error) {
if a.AccType != remote.ServiceWebDAV {
if a.AccType != service.WebDAV {
return false, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/workers/sync_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/mutex"
"github.com/photoprism/photoprism/internal/photoprism"
"github.com/photoprism/photoprism/internal/remote/webdav"
"github.com/photoprism/photoprism/internal/service/webdav"
"github.com/photoprism/photoprism/pkg/clean"
)

Expand Down

0 comments on commit c096382

Please sign in to comment.