// 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) }
// 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}) }
// 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)) }