Example #1
0
// NewFilePath sets a default path for this file.
func (m *File) NewFilePath(fh *multipart.FileHeader) error {
	m.Path = fmt.Sprintf("files/%d/%s", m.Id, file.SanitizeName(fh.Filename))
	params := map[string]string{"path": m.Path}
	return Query().Where("id=?", m.Id).Update(params)
}
Example #2
0
// NB this assumes that the path ends in .jpg
func (m *Image) SetDefaultOriginalPath() error {
	m.Path = fmt.Sprintf("files/images/%d/%s.jpg", m.Id, file.SanitizeName(m.Name))
	return m.Update(map[string]string{"path": m.Path})
}
Example #3
0
// CanonicalURL is the canonical URL of the story on this site
// including a slug for seo
func (m *Story) CanonicalURL() string {
	return fmt.Sprintf("/stories/%d-%s", m.Id, file.SanitizeName(m.Name))
}