mirror of
https://github.com/thiloho/archtika.git
synced 2025-11-22 10:51:36 +01:00
Add ability to export articles, track publications in json file on NGINX, fix vulnerabilities and refactor
This commit is contained in:
@@ -9,35 +9,28 @@ DECLARE
|
||||
_markdown_dir TEXT := '/tmp/website-' || export_articles_zip.website_id;
|
||||
BEGIN
|
||||
_has_access = internal.user_has_website_access (export_articles_zip.website_id, 20);
|
||||
|
||||
SELECT
|
||||
FORMAT('[{ "Content-Type": "application/gzip" },'
|
||||
'{ "Content-Disposition": "attachment; filename=\"%s\"" }]',
|
||||
'archtika-export-articles-' || export_articles_zip.website_id || '.tar.gz') INTO _headers;
|
||||
'{ "Content-Disposition": "attachment; filename=\"%s\"" }]', 'archtika-export-articles-' || export_articles_zip.website_id || '.tar.gz') INTO _headers;
|
||||
PERFORM
|
||||
SET_CONFIG('response.headers', _headers, TRUE);
|
||||
|
||||
EXECUTE FORMAT('COPY (SELECT '''') TO PROGRAM ''mkdir -p %s''', _markdown_dir || '/articles');
|
||||
|
||||
EXECUTE FORMAT('COPY (SELECT 1) TO PROGRAM ''mkdir -p %s''', _markdown_dir || '/articles');
|
||||
FOR _article IN (
|
||||
SELECT a.id, a.website_id, a.slug, a.main_content
|
||||
FROM internal.article AS a
|
||||
WHERE a.website_id = export_articles_zip.website_id)
|
||||
LOOP
|
||||
EXECUTE FORMAT(
|
||||
'COPY (SELECT %L) TO ''%s''',
|
||||
_article.main_content,
|
||||
_markdown_dir || '/articles/' || _article.slug || '.md'
|
||||
);
|
||||
END LOOP;
|
||||
|
||||
EXECUTE FORMAT('COPY (SELECT '''') TO PROGRAM ''tar -czf %s -C %s articles && rm %s''',
|
||||
_markdown_dir || '/export.tar.gz',
|
||||
_markdown_dir,
|
||||
_markdown_dir || '/articles/*.md'
|
||||
);
|
||||
|
||||
RETURN pg_read_binary_file(_markdown_dir || '/export.tar.gz');
|
||||
SELECT
|
||||
a.id,
|
||||
a.website_id,
|
||||
a.slug,
|
||||
a.main_content
|
||||
FROM
|
||||
internal.article AS a
|
||||
WHERE
|
||||
a.website_id = export_articles_zip.website_id)
|
||||
LOOP
|
||||
EXECUTE FORMAT('COPY (SELECT %L) TO ''%s'' WITH (FORMAT CSV)', COALESCE(_article.main_content, 'No content yet'), _markdown_dir || '/articles/' || _article.slug || '.md');
|
||||
EXECUTE FORMAT('COPY (SELECT 1) TO PROGRAM ''sed -i "s/^\"//;s/\"$//;s/\"\"/\"/g" %s''', _markdown_dir || '/articles/' || _article.slug || '.md');
|
||||
END LOOP;
|
||||
EXECUTE FORMAT('COPY (SELECT 1) TO PROGRAM ''tar -czf %s -C %s articles && rm %s''', _markdown_dir || '/export.tar.gz', _markdown_dir, _markdown_dir || '/articles/*.md');
|
||||
RETURN PG_READ_BINARY_FILE(_markdown_dir || '/export.tar.gz');
|
||||
END;
|
||||
$$
|
||||
LANGUAGE plpgsql
|
||||
@@ -47,3 +40,4 @@ GRANT EXECUTE ON FUNCTION api.export_articles_zip TO authenticated_user;
|
||||
|
||||
-- migrate:down
|
||||
DROP FUNCTION api.export_articles_zip;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user