Skip to content

Commit fadc386

Browse files
committed
Backup for links
1 parent 539d91f commit fadc386

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

app/routes/links._index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export default function Index() {
6363
<>
6464
<RemixLink to="/links/add.html" className="btn btn-primary mx-1"><AdminIcon /> Add</RemixLink>
6565
<RemixLink to="/links/import.html" className="btn btn-primary mx-1"><AdminIcon /> Import</RemixLink>
66+
<a href="/links/backup.json" className="btn btn-primary mx-1"><AdminIcon /> Backup</a>
6667
</>
6768
: null}
6869
</div>

app/routes/links.backup[.]json.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { desc } from "drizzle-orm";
2+
3+
import { dborm } from "~/db/connection.server";
4+
import { regex_link } from "~/db/schema";
5+
6+
export async function loader() {
7+
8+
const links = await dborm.select().from(regex_link).orderBy(desc(regex_link.rxl_created_at));
9+
10+
const jsonStr = JSON.stringify(links);
11+
12+
const date = new Date().toISOString().split('T')[0];
13+
14+
return new Response(jsonStr, {
15+
headers: {
16+
'Access-Control-Allow-Origin': '*',
17+
'Access-Control-Allow-Methods': 'POST, GET',
18+
'Access-Control-Max-Age': '604800',
19+
'Content-Type': 'application/json; charset=utf-8',
20+
'Content-Disposition': `attachment; filename="${date}-backup_rz_links.json"`,
21+
},
22+
});
23+
}

app/routes/links.import[.]html.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ export const action = async ({
6565
console.log(JSON.stringify(entry));
6666
const existing = await dborm.select().from(regex_link).where(eq(regex_link.rxl_url, entry.href));
6767
if (existing.length > 0) {
68-
console.log("skipping", entry.href);
69-
continue;
68+
console.log(`found ${entry.href}, stopping...`);
69+
break;
7070
}
7171
console.log("inserting", entry.href);
7272
await dborm.insert(regex_link).values({

0 commit comments

Comments
 (0)