Skip to content

Commit

Permalink
Merge pull request #128 from Maker-Management-Platform/latest
Browse files Browse the repository at this point in the history
Latest
  • Loading branch information
EduardoOliveira authored Apr 15, 2024
2 parents 82ae9ca + 3a14996 commit 1def746
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions core/downloader/thingiverse/thingiverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"net/url"
"regexp"
"strings"
"time"

"github.com/eduardooliveira/stLib/core/data/database"
Expand Down Expand Up @@ -42,6 +43,10 @@ func Fetch(url string) error {
return err
}

if p, err := database.GetProjectByPathAndName(project.Path, project.Name); err == nil && p.UUID != "" {
project.UUID = p.UUID
}

if err = utils.CreateFolder(utils.ToLibPath(project.FullPath())); err != nil {
log.Println("error creating project folder")
return err
Expand All @@ -65,12 +70,11 @@ func Fetch(url string) error {

project.Initialized = true

return database.InsertProject(project)
return database.UpdateProject(project)
}

func fetchDetails(id string, project *entities.Project, httpClient *http.Client) error {
u := &url.URL{Scheme: "https", Host: "api.thingiverse.com", Path: "/things/" + id}
project.ExternalLink = u.String()

req := &http.Request{
Method: "GET",
Expand All @@ -90,8 +94,9 @@ func fetchDetails(id string, project *entities.Project, httpClient *http.Client)
return err
}

project.Name = fmt.Sprintf("%d %s", thing.ID, thing.Name)
project.Name = strings.ReplaceAll(fmt.Sprintf("%d - %s", thing.ID, thing.Name), "/", "-")
project.Description = thing.Description
project.ExternalLink = thing.PublicURL

for _, tag := range thing.Tags {
project.Tags = append(project.Tags, entities.StringToTag(tag.Name))
Expand Down

0 comments on commit 1def746

Please sign in to comment.