Exemplo n.º 1
0
func importSubscriptions(pfc *PFContext, ch chan<- *rss.Outline, userID storage.UserID, parentRef storage.FolderRef, outlines []*rss.Outline) int {
	c := pfc.C

	count := 0
	for _, outline := range outlines {
		if outline.IsSubscription() {
			go importSubscription(pfc, ch, userID, parentRef, outline)
			count++
		} else if outline.IsFolder() {
			folderRef, err := storage.FolderByTitle(pfc.C, userID, outline.Title)
			if err != nil {
				c.Warningf("Error locating folder: %s", err)
				continue
			} else if folderRef.IsZero() {
				if folderRef, err = storage.CreateFolder(pfc.C, userID, outline.Title); err != nil {
					c.Warningf("Error locating folder: %s", err)
					continue
				}
			}

			count += importSubscriptions(pfc, ch, userID, folderRef, outline.Outlines)
		}
	}

	return count
}
Exemplo n.º 2
0
func createFolder(pfc *PFContext) (interface{}, error) {
	r := pfc.R

	title := r.PostFormValue("folderName")
	if title == "" {
		return nil, NewReadableError(_l("Missing folder name"), nil)
	}

	if utf8.RuneCountInString(title) > 200 {
		return nil, NewReadableError(_l("Folder name is too long"), nil)
	}

	if exists, err := storage.IsFolderDuplicate(pfc.C, pfc.UserID, title); err != nil {
		return nil, err
	} else if exists {
		return nil, NewReadableError(_l("A folder with that name already exists"), nil)
	}

	if _, err := storage.CreateFolder(pfc.C, pfc.UserID, title); err != nil {
		return nil, NewReadableError(_l("An error occurred while adding the new folder"), &err)
	}

	return storage.NewUserSubscriptions(pfc.C, pfc.UserID)
}