-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Archive snapshots of websites locally (#672)
* Add basic HTML snapshots * Implement asset list * Add snapshot creation tests * Add deletion tests * Show file size * Remove snapshots * Create new snapshots * Switch to single-file * CSS tweak * Remove auto refresh * Show delete link when there is no file yet * Add current date to display name * Add flag for snapshot support * Add option for disabling automatic snapshots * Make snapshots sharable * Document image variants * Update README.md * Add migrations * Fix tests
- Loading branch information
1 parent
db19069
commit 4280ab4
Showing
46 changed files
with
1,603 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { registerBehavior, swap } from "./index"; | ||
|
||
class FormBehavior { | ||
constructor(element) { | ||
this.element = element; | ||
element.addEventListener("submit", this.onFormSubmit.bind(this)); | ||
} | ||
|
||
async onFormSubmit(event) { | ||
event.preventDefault(); | ||
|
||
const url = this.element.action; | ||
const formData = new FormData(this.element); | ||
if (event.submitter) { | ||
formData.append(event.submitter.name, event.submitter.value); | ||
} | ||
|
||
await fetch(url, { | ||
method: "POST", | ||
body: formData, | ||
redirect: "manual", // ignore redirect | ||
}); | ||
|
||
// Dispatch refresh events | ||
const refreshEvents = this.element.getAttribute("refresh-events"); | ||
if (refreshEvents) { | ||
refreshEvents.split(",").forEach((eventName) => { | ||
document.dispatchEvent(new CustomEvent(eventName)); | ||
}); | ||
} | ||
|
||
// Refresh form | ||
await this.refresh(); | ||
} | ||
|
||
async refresh() { | ||
const refreshUrl = this.element.getAttribute("refresh-url"); | ||
const html = await fetch(refreshUrl).then((response) => response.text()); | ||
swap(this.element, html); | ||
} | ||
} | ||
|
||
class FormAutoSubmitBehavior { | ||
constructor(element) { | ||
this.element = element; | ||
this.element.addEventListener("change", () => { | ||
const form = this.element.closest("form"); | ||
form.dispatchEvent(new Event("submit", { cancelable: true })); | ||
}); | ||
} | ||
} | ||
|
||
registerBehavior("ld-form", FormBehavior); | ||
registerBehavior("ld-form-auto-submit", FormAutoSubmitBehavior); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Generated by Django 5.0.2 on 2024-03-31 08:21 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("bookmarks", "0029_bookmark_list_actions_toast"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="BookmarkAsset", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("date_created", models.DateTimeField(auto_now_add=True)), | ||
("file", models.CharField(blank=True, max_length=2048)), | ||
("file_size", models.IntegerField(null=True)), | ||
("asset_type", models.CharField(max_length=64)), | ||
("content_type", models.CharField(max_length=128)), | ||
("display_name", models.CharField(blank=True, max_length=2048)), | ||
("status", models.CharField(max_length=64)), | ||
("gzip", models.BooleanField(default=False)), | ||
( | ||
"bookmark", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="bookmarks.bookmark", | ||
), | ||
), | ||
], | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
bookmarks/migrations/0031_userprofile_enable_automatic_html_snapshots.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.0.2 on 2024-04-01 10:29 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("bookmarks", "0030_bookmarkasset"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="userprofile", | ||
name="enable_automatic_html_snapshots", | ||
field=models.BooleanField(default=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 5.0.2 on 2024-04-01 12:17 | ||
|
||
from django.db import migrations | ||
from django.contrib.auth import get_user_model | ||
|
||
from bookmarks.models import Toast | ||
|
||
User = get_user_model() | ||
|
||
|
||
def forwards(apps, schema_editor): | ||
|
||
for user in User.objects.all(): | ||
toast = Toast( | ||
key="html_snapshots_hint", | ||
message="This version adds a new feature for archiving snapshots of websites locally. To use it, you need to switch to a different Docker image. See the installation instructions on GitHub for details.", | ||
owner=user, | ||
) | ||
toast.save() | ||
|
||
|
||
def reverse(apps, schema_editor): | ||
Toast.objects.filter(key="bookmark_list_actions_hint").delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("bookmarks", "0031_userprofile_enable_automatic_html_snapshots"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(forwards, reverse), | ||
] |
Oops, something went wrong.