This commit is contained in:
@@ -31,7 +31,8 @@ type PostDTO struct {
|
||||
PostType string `json:"postType"`
|
||||
CategoryID int `json:"categoryId,omitempty"`
|
||||
CategorySlug string `json:"categorySlug,omitempty"`
|
||||
Language string `json:"language"`
|
||||
Language string `json:"language"` // UI locale from ?lang= (matches text selection)
|
||||
SourceLanguage string `json:"sourceLanguage,omitempty"` // DB source metadata (admin input language)
|
||||
Text string `json:"text,omitempty"`
|
||||
Localizations map[string]postLocalePayload `json:"localizations"`
|
||||
Attachments []AttachmentDTO `json:"attachments"`
|
||||
@@ -212,9 +213,9 @@ func translateNormalizePostLang(lang string) string {
|
||||
}
|
||||
|
||||
func validateAdminPost(ap *adminPost) error {
|
||||
ap.PostType = normalizePostType(ap.PostType)
|
||||
if ap.PostType == "" || !validPostTypes[ap.PostType] {
|
||||
return fmt.Errorf("postType required (image, video, music, ppt, pdf, link, text, archive)")
|
||||
ap.PostType = inferPostTypeFromContent(ap.Text, ap.Attachments)
|
||||
if !validPostTypes[ap.PostType] {
|
||||
ap.PostType = "text"
|
||||
}
|
||||
if len(ap.Attachments) > maxPostAttachments {
|
||||
return fmt.Errorf("too many attachments (max %d)", maxPostAttachments)
|
||||
@@ -389,11 +390,11 @@ func scanPostRow(r *http.Request, row pgx.Row) (PostDTO, postTextI18n, error) {
|
||||
var id uuid.UUID
|
||||
var catID *int
|
||||
var slug *string
|
||||
var lang, postType string
|
||||
var sourceLang, postType string
|
||||
var pub, updated, created *time.Time
|
||||
err := row.Scan(
|
||||
&id, &texts.TextZh, &texts.TextEn, &texts.TextJa, &texts.TextKo, &texts.TextVi, &texts.TextId, &texts.TextMs,
|
||||
&lang, &postType, &catID, &slug, &dto.IsRecommended, &pub, &updated, &created,
|
||||
&sourceLang, &postType, &catID, &slug, &dto.IsRecommended, &pub, &updated, &created,
|
||||
)
|
||||
if err != nil {
|
||||
return dto, texts, err
|
||||
@@ -406,7 +407,8 @@ func scanPostRow(r *http.Request, row pgx.Row) (PostDTO, postTextI18n, error) {
|
||||
if slug != nil {
|
||||
dto.CategorySlug = *slug
|
||||
}
|
||||
dto.Language = lang
|
||||
dto.SourceLanguage = sourceLang
|
||||
dto.Language = requestLangCode(r)
|
||||
dto.Text = texts.pick(r)
|
||||
dto.Localizations = texts.toLocalizations()
|
||||
if pub != nil {
|
||||
|
||||
Reference in New Issue
Block a user