- Implemented CredentialsDialog for updating user credentials. - Created auth store with functions for managing authentication state. - Added HealthWidget to display server health status. - Introduced health monitoring functionality with polling. - Developed AppShell layout to manage authentication and loading states. - Added SettingsDialog for user preferences including theme and language. - Created utility functions for list management and data fetching. - Implemented dashboard view mode preferences. - Integrated search functionality for filtering lists. - Established theme management with local storage support. - Added utility functions for class name management. - Configured SvelteKit for static site generation with fallback. - Set up Vite for development with proxy support for API calls. - Created About and List detail pages with data fetching and display. - Added favicon and updated project configuration files.
126 lines
3.4 KiB
Go
126 lines
3.4 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strconv"
|
|
)
|
|
|
|
// Timestamp accepts the millisecond timestamps emitted by the Android client as
|
|
// well as the older string/second-based representations accepted by the Node
|
|
// server. It marshals back as a JSON number for the mobile client.
|
|
type Timestamp int64
|
|
|
|
func (t *Timestamp) UnmarshalJSON(data []byte) error {
|
|
value := bytes.TrimSpace(data)
|
|
if len(value) == 0 || bytes.Equal(value, []byte("null")) {
|
|
*t = 0
|
|
return nil
|
|
}
|
|
|
|
if value[0] == '"' {
|
|
var stringValue string
|
|
if err := json.Unmarshal(value, &stringValue); err != nil {
|
|
return err
|
|
}
|
|
parsed, err := parseTimestamp(stringValue)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*t = Timestamp(parsed)
|
|
return nil
|
|
}
|
|
|
|
parsed, err := strconv.ParseFloat(string(value), 64)
|
|
if err != nil {
|
|
return fmt.Errorf("invalid timestamp %q: %w", string(value), err)
|
|
}
|
|
*t = Timestamp(parsed)
|
|
return nil
|
|
}
|
|
|
|
func parseTimestamp(value string) (int64, error) {
|
|
if numeric, err := strconv.ParseFloat(value, 64); err == nil {
|
|
return int64(numeric), nil
|
|
}
|
|
return 0, fmt.Errorf("invalid timestamp %q", value)
|
|
}
|
|
|
|
type List struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
CreatedAt Timestamp `json:"createdAt"`
|
|
UpdatedAt Timestamp `json:"updatedAt"`
|
|
IsDeleted bool `json:"isDeleted"`
|
|
}
|
|
|
|
type Field struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
FieldType string `json:"fieldType"`
|
|
FieldOptions string `json:"fieldOptions"`
|
|
Alignment string `json:"alignment"`
|
|
ListID string `json:"listId"`
|
|
Order int `json:"order"`
|
|
CreatedAt Timestamp `json:"createdAt"`
|
|
UpdatedAt Timestamp `json:"updatedAt"`
|
|
IsDeleted bool `json:"isDeleted"`
|
|
}
|
|
|
|
type Item struct {
|
|
ID string `json:"id"`
|
|
ListID string `json:"listId"`
|
|
CreatedAt Timestamp `json:"createdAt"`
|
|
UpdatedAt Timestamp `json:"updatedAt"`
|
|
IsDeleted bool `json:"isDeleted"`
|
|
}
|
|
|
|
type ItemValue struct {
|
|
ID string `json:"id"`
|
|
ItemID string `json:"itemId"`
|
|
FieldID string `json:"fieldId"`
|
|
Value string `json:"value"`
|
|
UpdatedAt Timestamp `json:"updatedAt"`
|
|
}
|
|
|
|
type SyncRequest struct {
|
|
LastSyncTimestamp Timestamp `json:"lastSyncTimestamp"`
|
|
Lists []List `json:"lists"`
|
|
Fields []Field `json:"fields"`
|
|
Items []Item `json:"items"`
|
|
ItemValues []ItemValue `json:"itemValues"`
|
|
DeviceID string `json:"deviceId,omitempty"`
|
|
}
|
|
|
|
type SyncResponse struct {
|
|
Lists []List `json:"lists"`
|
|
Fields []Field `json:"fields"`
|
|
Items []Item `json:"items"`
|
|
ItemValues []ItemValue `json:"itemValues"`
|
|
OrphanItemValues []OrphanValue `json:"orphanItemValues"`
|
|
ServerTimestamp int64 `json:"serverTimestamp"`
|
|
}
|
|
|
|
type OrphanValue struct {
|
|
ID string `json:"id"`
|
|
ItemID string `json:"itemId"`
|
|
FieldID string `json:"fieldId"`
|
|
Reason string `json:"reason"`
|
|
}
|
|
|
|
type NotificationEvent struct {
|
|
ID string `json:"id"`
|
|
DeviceIDOrigin string `json:"deviceIdOrigin,omitempty"`
|
|
EventType string `json:"eventType"`
|
|
EntityType string `json:"entityType"`
|
|
EntityID string `json:"entityId,omitempty"`
|
|
ListID string `json:"listId,omitempty"`
|
|
CreatedAt int64 `json:"createdAt"`
|
|
}
|
|
|
|
type PollResponse struct {
|
|
Notifications []NotificationEvent `json:"notifications"`
|
|
ServerTimestamp int64 `json:"serverTimestamp"`
|
|
}
|