Write on the margins of the internet. Powered by the AT Protocol. margin.at
extension web atproto comments

gofmt

+48 -56
+12 -16
backend/internal/api/moderation.go
··· 110 json.NewEncoder(w).Encode(map[string]interface{}{"items": items}) 111 } 112 113 - 114 func (m *ModerationHandler) MuteUser(w http.ResponseWriter, r *http.Request) { 115 session, err := m.refresher.GetSessionWithAutoRefresh(r) 116 if err != nil { ··· 225 }) 226 } 227 228 - 229 func (m *ModerationHandler) CreateReport(w http.ResponseWriter, r *http.Request) { 230 session, err := m.refresher.GetSessionWithAutoRefresh(r) 231 if err != nil { ··· 250 } 251 252 validReasons := map[string]bool{ 253 - "spam": true, 254 - "violation": true, 255 - "misleading": true, 256 - "sexual": true, 257 - "rude": true, 258 - "other": true, 259 } 260 261 if !validReasons[req.ReasonType] { ··· 274 json.NewEncoder(w).Encode(map[string]interface{}{"id": id, "status": "ok"}) 275 } 276 277 - 278 func (m *ModerationHandler) AdminGetReports(w http.ResponseWriter, r *http.Request) { 279 session, err := m.refresher.GetSessionWithAutoRefresh(r) 280 if err != nil { ··· 477 m.db.Exec("DELETE FROM replies WHERE uri = $1", uri) 478 } 479 480 - 481 func (m *ModerationHandler) AdminCreateLabel(w http.ResponseWriter, r *http.Request) { 482 session, err := m.refresher.GetSessionWithAutoRefresh(r) 483 if err != nil { ··· 607 profiles := fetchProfilesForDIDs(m.db, dids) 608 609 type HydratedLabel struct { 610 - ID int `json:"id"` 611 - Src string `json:"src"` 612 - URI string `json:"uri"` 613 - Val string `json:"val"` 614 - CreatedBy Author `json:"createdBy"` 615 - CreatedAt string `json:"createdAt"` 616 Subject *Author `json:"subject,omitempty"` 617 } 618
··· 110 json.NewEncoder(w).Encode(map[string]interface{}{"items": items}) 111 } 112 113 func (m *ModerationHandler) MuteUser(w http.ResponseWriter, r *http.Request) { 114 session, err := m.refresher.GetSessionWithAutoRefresh(r) 115 if err != nil { ··· 224 }) 225 } 226 227 func (m *ModerationHandler) CreateReport(w http.ResponseWriter, r *http.Request) { 228 session, err := m.refresher.GetSessionWithAutoRefresh(r) 229 if err != nil { ··· 248 } 249 250 validReasons := map[string]bool{ 251 + "spam": true, 252 + "violation": true, 253 + "misleading": true, 254 + "sexual": true, 255 + "rude": true, 256 + "other": true, 257 } 258 259 if !validReasons[req.ReasonType] { ··· 272 json.NewEncoder(w).Encode(map[string]interface{}{"id": id, "status": "ok"}) 273 } 274 275 func (m *ModerationHandler) AdminGetReports(w http.ResponseWriter, r *http.Request) { 276 session, err := m.refresher.GetSessionWithAutoRefresh(r) 277 if err != nil { ··· 474 m.db.Exec("DELETE FROM replies WHERE uri = $1", uri) 475 } 476 477 func (m *ModerationHandler) AdminCreateLabel(w http.ResponseWriter, r *http.Request) { 478 session, err := m.refresher.GetSessionWithAutoRefresh(r) 479 if err != nil { ··· 603 profiles := fetchProfilesForDIDs(m.db, dids) 604 605 type HydratedLabel struct { 606 + ID int `json:"id"` 607 + Src string `json:"src"` 608 + URI string `json:"uri"` 609 + Val string `json:"val"` 610 + CreatedBy Author `json:"createdBy"` 611 + CreatedAt string `json:"createdAt"` 612 Subject *Author `json:"subject,omitempty"` 613 } 614
+2 -2
backend/internal/api/preferences.go
··· 23 24 type PreferencesResponse struct { 25 ExternalLinkSkippedHostnames []string `json:"externalLinkSkippedHostnames"` 26 - SubscribedLabelers []LabelerSubscription `json:"subscribedLabelers"` 27 - LabelPreferences []LabelPreference `json:"labelPreferences"` 28 } 29 30 func (h *Handler) GetPreferences(w http.ResponseWriter, r *http.Request) {
··· 23 24 type PreferencesResponse struct { 25 ExternalLinkSkippedHostnames []string `json:"externalLinkSkippedHostnames"` 26 + SubscribedLabelers []LabelerSubscription `json:"subscribedLabelers"` 27 + LabelPreferences []LabelPreference `json:"labelPreferences"` 28 } 29 30 func (h *Handler) GetPreferences(w http.ResponseWriter, r *http.Request) {
+16 -16
backend/internal/db/db.go
··· 171 } 172 173 type ModerationReport struct { 174 - ID int `json:"id"` 175 - ReporterDID string `json:"reporterDid"` 176 - SubjectDID string `json:"subjectDid"` 177 - SubjectURI *string `json:"subjectUri,omitempty"` 178 - ReasonType string `json:"reasonType"` 179 - ReasonText *string `json:"reasonText,omitempty"` 180 - Status string `json:"status"` 181 - CreatedAt time.Time `json:"createdAt"` 182 - ResolvedAt *time.Time `json:"resolvedAt,omitempty"` 183 - ResolvedBy *string `json:"resolvedBy,omitempty"` 184 } 185 186 type ModerationAction struct { 187 - ID int `json:"id"` 188 - ReportID int `json:"reportId"` 189 - ActorDID string `json:"actorDid"` 190 - Action string `json:"action"` 191 - Comment *string `json:"comment,omitempty"` 192 - CreatedAt time.Time `json:"createdAt"` 193 } 194 195 type ContentLabel struct {
··· 171 } 172 173 type ModerationReport struct { 174 + ID int `json:"id"` 175 + ReporterDID string `json:"reporterDid"` 176 + SubjectDID string `json:"subjectDid"` 177 + SubjectURI *string `json:"subjectUri,omitempty"` 178 + ReasonType string `json:"reasonType"` 179 + ReasonText *string `json:"reasonText,omitempty"` 180 + Status string `json:"status"` 181 + CreatedAt time.Time `json:"createdAt"` 182 + ResolvedAt *time.Time `json:"resolvedAt,omitempty"` 183 + ResolvedBy *string `json:"resolvedBy,omitempty"` 184 } 185 186 type ModerationAction struct { 187 + ID int `json:"id"` 188 + ReportID int `json:"reportId"` 189 + ActorDID string `json:"actorDid"` 190 + Action string `json:"action"` 191 + Comment *string `json:"comment,omitempty"` 192 + CreatedAt time.Time `json:"createdAt"` 193 } 194 195 type ContentLabel struct {
-4
backend/internal/db/queries_moderation.go
··· 2 3 import "time" 4 5 - 6 func (db *DB) CreateBlock(actorDID, subjectDID string) error { 7 query := `INSERT INTO blocks (actor_did, subject_did, created_at) VALUES (?, ?, ?) 8 ON CONFLICT(actor_did, subject_did) DO NOTHING` ··· 80 } 81 return dids, nil 82 } 83 - 84 85 func (db *DB) CreateMute(actorDID, subjectDID string) error { 86 query := `INSERT INTO mutes (actor_did, subject_did, created_at) VALUES (?, ?, ?) ··· 188 return 189 } 190 191 - 192 func (db *DB) CreateReport(reporterDID, subjectDID string, subjectURI *string, reasonType string, reasonText *string) (int, error) { 193 query := `INSERT INTO moderation_reports (reporter_did, subject_did, subject_uri, reason_type, reason_text, status, created_at) 194 VALUES (?, ?, ?, ?, ?, 'pending', ?)` ··· 283 err := db.QueryRow(db.Rebind(query), args...).Scan(&count) 284 return count, err 285 } 286 - 287 288 func (db *DB) CreateContentLabel(src, uri, val, createdBy string) error { 289 query := `INSERT INTO content_labels (src, uri, val, neg, created_by, created_at) VALUES (?, ?, ?, 0, ?, ?)`
··· 2 3 import "time" 4 5 func (db *DB) CreateBlock(actorDID, subjectDID string) error { 6 query := `INSERT INTO blocks (actor_did, subject_did, created_at) VALUES (?, ?, ?) 7 ON CONFLICT(actor_did, subject_did) DO NOTHING` ··· 79 } 80 return dids, nil 81 } 82 83 func (db *DB) CreateMute(actorDID, subjectDID string) error { 84 query := `INSERT INTO mutes (actor_did, subject_did, created_at) VALUES (?, ?, ?) ··· 186 return 187 } 188 189 func (db *DB) CreateReport(reporterDID, subjectDID string, subjectURI *string, reasonType string, reasonText *string) (int, error) { 190 query := `INSERT INTO moderation_reports (reporter_did, subject_did, subject_uri, reason_type, reason_text, status, created_at) 191 VALUES (?, ?, ?, ?, ?, 'pending', ?)` ··· 280 err := db.QueryRow(db.Rebind(query), args...).Scan(&count) 281 return count, err 282 } 283 284 func (db *DB) CreateContentLabel(src, uri, val, createdBy string) error { 285 query := `INSERT INTO content_labels (src, uri, val, neg, created_by, created_at) VALUES (?, ?, ?, 0, ?, ?)`
+7 -7
backend/internal/sync/service.go
··· 189 } else { 190 err = e 191 } 192 - case xrpc.CollectionAPIKey: 193 - localURIs, err = s.db.GetAPIKeyURIs(did) 194 - localURIs = filterURIsByCollection(localURIs, xrpc.CollectionAPIKey) 195 - case xrpc.CollectionPreferences: 196 - localURIs, err = s.db.GetPreferenceURIs(did) 197 - localURIs = filterURIsByCollection(localURIs, xrpc.CollectionPreferences) 198 - case xrpc.CollectionSembleCollectionLink: 199 items, e := s.db.GetCollectionItemsByAuthor(did) 200 if e == nil { 201 for _, item := range items {
··· 189 } else { 190 err = e 191 } 192 + case xrpc.CollectionAPIKey: 193 + localURIs, err = s.db.GetAPIKeyURIs(did) 194 + localURIs = filterURIsByCollection(localURIs, xrpc.CollectionAPIKey) 195 + case xrpc.CollectionPreferences: 196 + localURIs, err = s.db.GetPreferenceURIs(did) 197 + localURIs = filterURIsByCollection(localURIs, xrpc.CollectionPreferences) 198 + case xrpc.CollectionSembleCollectionLink: 199 items, e := s.db.GetCollectionItemsByAuthor(did) 200 if e == nil { 201 for _, item := range items {
+11 -11
backend/internal/xrpc/records.go
··· 332 } 333 334 type BookmarkRecord struct { 335 - Type string `json:"$type"` 336 - Source string `json:"source"` 337 - SourceHash string `json:"sourceHash"` 338 - Title string `json:"title,omitempty"` 339 - Description string `json:"description,omitempty"` 340 - Tags []string `json:"tags,omitempty"` 341 - Generator *Generator `json:"generator,omitempty"` 342 - Rights string `json:"rights,omitempty"` 343 Labels *SelfLabels `json:"labels,omitempty"` 344 - CreatedAt string `json:"createdAt"` 345 } 346 347 func (r *BookmarkRecord) Validate() error { ··· 474 type PreferencesRecord struct { 475 Type string `json:"$type"` 476 ExternalLinkSkippedHostnames []string `json:"externalLinkSkippedHostnames,omitempty"` 477 - SubscribedLabelers []LabelerSubscription `json:"subscribedLabelers,omitempty"` 478 - LabelPreferences []LabelPreference `json:"labelPreferences,omitempty"` 479 CreatedAt string `json:"createdAt"` 480 } 481
··· 332 } 333 334 type BookmarkRecord struct { 335 + Type string `json:"$type"` 336 + Source string `json:"source"` 337 + SourceHash string `json:"sourceHash"` 338 + Title string `json:"title,omitempty"` 339 + Description string `json:"description,omitempty"` 340 + Tags []string `json:"tags,omitempty"` 341 + Generator *Generator `json:"generator,omitempty"` 342 + Rights string `json:"rights,omitempty"` 343 Labels *SelfLabels `json:"labels,omitempty"` 344 + CreatedAt string `json:"createdAt"` 345 } 346 347 func (r *BookmarkRecord) Validate() error { ··· 474 type PreferencesRecord struct { 475 Type string `json:"$type"` 476 ExternalLinkSkippedHostnames []string `json:"externalLinkSkippedHostnames,omitempty"` 477 + SubscribedLabelers []LabelerSubscription `json:"subscribedLabelers,omitempty"` 478 + LabelPreferences []LabelPreference `json:"labelPreferences,omitempty"` 479 CreatedAt string `json:"createdAt"` 480 } 481