@@ 176,7 176,7 @@ func (i importAdapter) GetType() int {
return i.elementType
}
-func processBaseURLs(obj importObj, tmpURLMap map[string]bool, urlList []string, domain string) {
+func processBaseURLs(obj importObj, tmpURLMap map[string]bool, urlList []string, c echo.Context) {
importedURL, err := url.ParseRequestURI(obj.GetURL())
if err != nil {
return
@@ 185,7 185,7 @@ func processBaseURLs(obj importObj, tmpURLMap map[string]bool, urlList []string,
// then process base and link import as usual
if importedURL.Hostname() == "notes.pinboard.in" {
// Create a new note url
- noteURL, noteHash := links.CreateNoteURL(domain)
+ noteURL, noteHash := links.CreateNoteURL(c)
obj.SetURL(noteURL)
obj.SetIsNote(true)
obj.SetNoteHash(noteHash)
@@ 199,18 199,18 @@ func processBaseURLs(obj importObj, tmpURLMap map[string]bool, urlList []string,
// Get a importAdapter with a list of pinBoardObj, HTMLObj and FirefoxObj
// and create the base url objects in the db
// returns a map containing the base url as index and its id as value
-func importBaseURLs(ctx context.Context, objAdapter *importAdapter, domain string) (map[string]int, error) {
+func importBaseURLs(c echo.Context, objAdapter *importAdapter) (map[string]int, error) {
urlList := make([]string, 0)
tmpURLMap := make(map[string]bool) // temporary map to store non existing url
baseURLMap := make(map[string]int)
switch objAdapter.GetType() {
case pinBoardType:
for _, obj := range objAdapter.GetPinBoards() {
- processBaseURLs(obj, tmpURLMap, urlList, domain)
+ processBaseURLs(obj, tmpURLMap, urlList, c)
}
case htmlType:
for _, obj := range objAdapter.GetHTMLLinks() {
- processBaseURLs(obj, tmpURLMap, urlList, domain)
+ processBaseURLs(obj, tmpURLMap, urlList, c)
}
}
@@ 218,6 218,7 @@ func importBaseURLs(ctx context.Context, objAdapter *importAdapter, domain strin
opts := &database.FilterOptions{
Filter: sq.Eq{"b.url": urlList},
}
+ ctx := c.Request().Context()
baseURLs, err := models.GetBaseURLs(ctx, opts)
if err != nil {
return nil, err
@@ 327,7 328,6 @@ func ImportFromPinBoard(c echo.Context, src multipart.File,
gctx := c.(*server.Context)
billEnabled := links.BillingEnabled(gctx.Server.Config)
- domain := links.GetLinksDomain(c)
for start < len(pinBoardList) {
if end+step > len(pinBoardList) {
@@ 337,7 337,7 @@ func ImportFromPinBoard(c echo.Context, src multipart.File,
}
adapter.start = start
adapter.end = end
- baseURLMap, err := importBaseURLs(c.Request().Context(), adapter, domain)
+ baseURLMap, err := importBaseURLs(c, adapter)
if err != nil {
return err
}
@@ 428,7 428,7 @@ func ImportFromHTML(c echo.Context, src multipart.File,
}
adapter.start = start
adapter.end = end
- baseURLMap, err := importBaseURLs(c.Request().Context(), adapter, "")
+ baseURLMap, err := importBaseURLs(c, adapter)
if err != nil {
return err
}
@@ 679,11 679,12 @@ func ProcessTags(ctx context.Context, tags []string) ([]int, error) {
return tagIDs, nil
}
-func CreateNoteURL(domain string) (string, string) {
- domain = strings.ToLower(domain)
+func CreateNoteURL(c echo.Context) (string, string) {
+ gctx := c.(*server.Context)
+ domain := strings.ToLower(GetLinksDomain(c))
noteHash := ksuid.New().String()
noteURL := &url.URL{
- Scheme: "https",
+ Scheme: gctx.Server.Config.Scheme,
Host: domain,
Path: fmt.Sprintf("/note/%s", noteHash),
}