Use file extension to access different catalog formats

merge-requests/30/head
Bob Mottram 2021-07-25 15:19:04 +01:00
parent 504101d17e
commit 336c7e8bbb
1 changed files with 32 additions and 25 deletions

View File

@ -10679,20 +10679,13 @@ class PubServer(BaseHTTPRequestHandler):
catalogAuthorized = True catalogAuthorized = True
# show shared items DFC catalog # show shared items DFC catalog
if self._hasAccept(callingDomain) and catalogAuthorized: if self._hasAccept(callingDomain) and catalogAuthorized:
if not self._requestHTTP(): catalogType = 'html'
if self._requestCSV(): if self.path.endswith('.csv') or self._requestCSV():
# catalog as a CSV file for import into a spreadsheet catalogType = 'csv'
catalogStr = \ elif self.path.endswith('.json') or not self._requestHTTP():
sharesCatalogCSVEndpoint(self.server.baseDir, catalogType = 'json'
self.server.httpPrefix,
self.server.domainFull, if catalogType == 'json':
self.server.path)
msg = json.dumps(catalogStr,
ensure_ascii=False).encode('utf-8')
msglen = len(msg)
self._set_headers('text/csv',
msglen, None, callingDomain)
else:
# catalog as a json # catalog as a json
catalogJson = \ catalogJson = \
sharesCatalogEndpoint(self.server.baseDir, sharesCatalogEndpoint(self.server.baseDir,
@ -10706,6 +10699,20 @@ class PubServer(BaseHTTPRequestHandler):
msglen, None, callingDomain) msglen, None, callingDomain)
self._write(msg) self._write(msg)
return return
elif catalogType == 'csv':
# catalog as a CSV file for import into a spreadsheet
catalogStr = \
sharesCatalogCSVEndpoint(self.server.baseDir,
self.server.httpPrefix,
self.server.domainFull,
self.server.path)
msg = json.dumps(catalogStr,
ensure_ascii=False).encode('utf-8')
msglen = len(msg)
self._set_headers('text/csv',
msglen, None, callingDomain)
self._write(msg)
return
self.path = '/' self.path = '/'
# minimal mastodon api # minimal mastodon api