fix orphans
This commit is contained in:
@@ -102,7 +102,7 @@ func (b *DBBackend) initSchema(ctx context.Context) error {
|
|||||||
)`,
|
)`,
|
||||||
`CREATE TABLE IF NOT EXISTS calendar_objects (
|
`CREATE TABLE IF NOT EXISTS calendar_objects (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
calendar_id INTEGER REFERENCES calendars(id) ON DELETE CASCADE,
|
calendar_id INTEGER NOT NULL REFERENCES calendars(id) ON DELETE CASCADE,
|
||||||
path TEXT NOT NULL,
|
path TEXT NOT NULL,
|
||||||
data TEXT NOT NULL,
|
data TEXT NOT NULL,
|
||||||
etag TEXT NOT NULL,
|
etag TEXT NOT NULL,
|
||||||
@@ -110,20 +110,20 @@ func (b *DBBackend) initSchema(ctx context.Context) error {
|
|||||||
)`,
|
)`,
|
||||||
`CREATE TABLE IF NOT EXISTS addressbooks (
|
`CREATE TABLE IF NOT EXISTS addressbooks (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
owner_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
|
owner_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
path TEXT UNIQUE NOT NULL,
|
path TEXT UNIQUE NOT NULL,
|
||||||
name TEXT,
|
name TEXT,
|
||||||
description TEXT
|
description TEXT
|
||||||
)`,
|
)`,
|
||||||
`CREATE TABLE IF NOT EXISTS addressbook_access (
|
`CREATE TABLE IF NOT EXISTS addressbook_access (
|
||||||
addressbook_id INTEGER REFERENCES addressbooks(id) ON DELETE CASCADE,
|
addressbook_id INTEGER NOT NULL REFERENCES addressbooks(id) ON DELETE CASCADE,
|
||||||
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
|
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||||
mode TEXT NOT NULL,
|
mode TEXT NOT NULL,
|
||||||
PRIMARY KEY (addressbook_id, user_id)
|
PRIMARY KEY (addressbook_id, user_id)
|
||||||
)`,
|
)`,
|
||||||
`CREATE TABLE IF NOT EXISTS addressbook_objects (
|
`CREATE TABLE IF NOT EXISTS addressbook_objects (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
addressbook_id INTEGER REFERENCES addressbooks(id) ON DELETE CASCADE,
|
addressbook_id INTEGER NOT NULL REFERENCES addressbooks(id) ON DELETE CASCADE,
|
||||||
path TEXT NOT NULL,
|
path TEXT NOT NULL,
|
||||||
data TEXT NOT NULL,
|
data TEXT NOT NULL,
|
||||||
etag TEXT NOT NULL,
|
etag TEXT NOT NULL,
|
||||||
|
|||||||
@@ -39,9 +39,19 @@ func InjectColor(r *http.Request, ctx context.Context, handler http.Handler, w h
|
|||||||
body := buf.Bytes()
|
body := buf.Bytes()
|
||||||
|
|
||||||
// this models after the Radicale Response, largely AI code
|
// this models after the Radicale Response, largely AI code
|
||||||
// 1. Add namespaces to the root multistatus tag
|
// 1. Add namespaces to the root multistatus tag only if they are missing
|
||||||
reMultistatus := regexp.MustCompile(`(<[a-zA-Z0-9]*:?multistatus)`)
|
if !bytes.Contains(body, []byte("xmlns:ICAL=")) {
|
||||||
body = reMultistatus.ReplaceAll(body, []byte(`$1 xmlns:ICAL="http://apple.com/ns/ical/" xmlns:C="urn:ietf:params:xml:ns:caldav" xmlns:CS="http://calendarserver.org/ns/"`))
|
reMultistatus := regexp.MustCompile(`(<[a-zA-Z0-9]*:?multistatus)`)
|
||||||
|
body = reMultistatus.ReplaceAll(body, []byte(`$1 xmlns:ICAL="http://apple.com/ns/ical/"`))
|
||||||
|
}
|
||||||
|
if !bytes.Contains(body, []byte("xmlns:C=")) && !bytes.Contains(body, []byte("xmlns:c=")) {
|
||||||
|
reMultistatus := regexp.MustCompile(`(<[a-zA-Z0-9]*:?multistatus)`)
|
||||||
|
body = reMultistatus.ReplaceAll(body, []byte(`$1 xmlns:C="urn:ietf:params:xml:ns:caldav"`))
|
||||||
|
}
|
||||||
|
if !bytes.Contains(body, []byte("xmlns:CS=")) {
|
||||||
|
reMultistatus := regexp.MustCompile(`(<[a-zA-Z0-9]*:?multistatus)`)
|
||||||
|
body = reMultistatus.ReplaceAll(body, []byte(`$1 xmlns:CS="http://calendarserver.org/ns/"`))
|
||||||
|
}
|
||||||
|
|
||||||
// 2. Response processing
|
// 2. Response processing
|
||||||
reResponse := regexp.MustCompile(`(?s)<[a-zA-Z0-9]*:?response.*?>.*?</[a-zA-Z0-9]*:?response>`)
|
reResponse := regexp.MustCompile(`(?s)<[a-zA-Z0-9]*:?response.*?>.*?</[a-zA-Z0-9]*:?response>`)
|
||||||
@@ -62,7 +72,7 @@ func InjectColor(r *http.Request, ctx context.Context, handler http.Handler, w h
|
|||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. Strip any existing conflicting tags that might be in 404 blocks
|
// 1. Strip any existing conflicting tags that might be in 404 blocks (non-greedy)
|
||||||
reStrip := regexp.MustCompile(`(?s)<[a-zA-Z0-9]*:?(calendar-color|getctag|calendar-order).*?/>|<[a-zA-Z0-9]*:?(calendar-color|getctag|calendar-order).*?>.*?</[a-zA-Z0-9]*:?(calendar-color|getctag|calendar-order)>`)
|
reStrip := regexp.MustCompile(`(?s)<[a-zA-Z0-9]*:?(calendar-color|getctag|calendar-order).*?/>|<[a-zA-Z0-9]*:?(calendar-color|getctag|calendar-order).*?>.*?</[a-zA-Z0-9]*:?(calendar-color|getctag|calendar-order)>`)
|
||||||
resp = reStrip.ReplaceAll(resp, []byte(""))
|
resp = reStrip.ReplaceAll(resp, []byte(""))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user