1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00

Remove the paste-specific autoDelete field

This commit is contained in:
Lukas Schulte Pelkum 2021-07-30 21:51:33 +02:00
parent 4f3b5b193b
commit 1818fac196
No known key found for this signature in database
GPG Key ID: 408DA7CA81DB885C
12 changed files with 28 additions and 30 deletions

5
API.md
View File

@ -35,8 +35,6 @@ The central paste entity has the following fields:
* `modificationToken` (string)
* The token used to authenticate with paste-specific secured endpoints; stored hashed and only returned on initial paste creation
* `created` (int64; UNIX timestamp)
* `autoDelete` (boolean)
* The AutoDelete feature works on a paste-specific basis (even if you turn it off, pastes created while it was on will still be automatically deleted)
* `metadata` (key-value store)
* Different frontends may store simple key-value metadata pairs on pastes to enable specific functionality (for example clientside encryption)
@ -94,7 +92,6 @@ none
"id": "paste_id",
"content": "paste_content",
"created": 0000000000,
"autoDelete": false,
"metadata": {},
}
```
@ -122,7 +119,6 @@ POST /api/v2/pastes
"content": "paste_content",
"modificationToken": "raw_modification_token",
"created": 0000000000,
"autoDelete": false,
"metadata": {},
}
```
@ -149,7 +145,6 @@ PATCH /api/v2/pastes/{paste_id}
"id": "paste_id",
"content": "new_paste_content",
"created": 0000000000,
"autoDelete": false,
"metadata": {},
}
```

View File

@ -13,7 +13,6 @@ type Paste struct {
DeletionToken string `json:"deletionToken,omitempty" bson:"deletionToken"` // Required for legacy paste storage support
ModificationToken string `json:"modificationToken,omitempty" bson:"modificationToken"`
Created int64 `json:"created" bson:"created"`
AutoDelete bool `json:"autoDelete" bson:"autoDelete"`
Metadata map[string]interface{} `json:"metadata" bson:"metadata"`
}

View File

@ -133,7 +133,7 @@ func (driver *FileDriver) Cleanup() (int, error) {
// Delete the paste if it is expired
lifetime := config.Current.AutoDelete.Lifetime
if paste.AutoDelete && paste.Created+int64(lifetime.Seconds()) < time.Now().Unix() {
if paste.Created+int64(lifetime.Seconds()) < time.Now().Unix() {
err = driver.Delete(id)
if err != nil {
return deleted, err

View File

@ -159,7 +159,7 @@ func (driver *MongoDBDriver) Cleanup() (int, error) {
// Delete the paste if it is expired
lifetime := config.Current.AutoDelete.Lifetime
if paste.AutoDelete && paste.Created+int64(lifetime.Seconds()) < time.Now().Unix() {
if paste.Created+int64(lifetime.Seconds()) < time.Now().Unix() {
err = driver.Delete(id)
if err != nil {
return 0, err

View File

@ -0,0 +1,5 @@
begin;
alter table if exists "pastes" add column "autoDelete" boolean;
commit;

View File

@ -0,0 +1,5 @@
begin;
alter table if exists "pastes" drop column "autoDelete";
commit;

View File

@ -82,7 +82,7 @@ func (driver *PostgresDriver) Get(id string) (*shared.Paste, error) {
row := driver.pool.QueryRow(context.Background(), query, id)
paste := new(shared.Paste)
if err := row.Scan(&paste.ID, &paste.Content, &paste.ModificationToken, &paste.Created, &paste.AutoDelete, &paste.Metadata); err != nil {
if err := row.Scan(&paste.ID, &paste.Content, &paste.ModificationToken, &paste.Created, &paste.Metadata); err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return nil, nil
}
@ -94,17 +94,16 @@ func (driver *PostgresDriver) Get(id string) (*shared.Paste, error) {
// Save saves a paste
func (driver *PostgresDriver) Save(paste *shared.Paste) error {
query := `
INSERT INTO pastes (id, content, "modificationToken", created, "autoDelete", metadata)
VALUES ($1, $2, $3, $4, $5, $6)
INSERT INTO pastes (id, content, "modificationToken", created, metadata)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (id) DO UPDATE
SET content = excluded.content,
"modificationToken" = excluded."modificationToken",
created = excluded.created,
"autoDelete" = excluded."autoDelete",
metadata = excluded.metadata
`
_, err := driver.pool.Exec(context.Background(), query, paste.ID, paste.Content, paste.ModificationToken, paste.Created, paste.AutoDelete, paste.Metadata)
_, err := driver.pool.Exec(context.Background(), query, paste.ID, paste.Content, paste.ModificationToken, paste.Created, paste.Metadata)
return err
}
@ -118,7 +117,7 @@ func (driver *PostgresDriver) Delete(id string) error {
// Cleanup cleans up the expired pastes
func (driver *PostgresDriver) Cleanup() (int, error) {
query := "DELETE FROM pastes WHERE autoDelete = true AND created < $2"
query := "DELETE FROM pastes WHERE created < $2"
tag, err := driver.pool.Exec(context.Background(), query, time.Now().Add(-config.Current.AutoDelete.Lifetime).Unix())
if err != nil {

View File

@ -124,7 +124,7 @@ func (driver *S3Driver) Cleanup() (int, error) {
// Delete the paste if it is expired
lifetime := config.Current.AutoDelete.Lifetime
if paste.AutoDelete && paste.Created+int64(lifetime.Seconds()) < time.Now().Unix() {
if paste.Created+int64(lifetime.Seconds()) < time.Now().Unix() {
err = driver.Delete(id)
if err != nil {
return 0, err

View File

@ -47,7 +47,6 @@ func HastebinSupportHandler(ctx *fasthttp.RequestCtx) {
ID: id,
Content: content,
Created: time.Now().Unix(),
AutoDelete: config.Current.AutoDelete.Enabled,
}
// Set a modification token

View File

@ -7,7 +7,6 @@ type legacyPaste struct {
Content string `json:"content"`
DeletionToken string `json:"deletionToken,omitempty"`
Created int64 `json:"created"`
AutoDelete bool `json:"autoDelete"`
}
func legacyFromModern(paste *shared.Paste) *legacyPaste {
@ -21,6 +20,5 @@ func legacyFromModern(paste *shared.Paste) *legacyPaste {
Content: paste.Content,
DeletionToken: deletionToken,
Created: paste.Created,
AutoDelete: paste.AutoDelete,
}
}

View File

@ -89,7 +89,6 @@ func v1PostPaste(ctx *fasthttp.RequestCtx) {
ID: id,
Content: values["content"],
Created: time.Now().Unix(),
AutoDelete: config.Current.AutoDelete.Enabled,
}
// Set a modification token

View File

@ -139,7 +139,6 @@ func endpointCreatePaste(ctx *fasthttp.RequestCtx) {
ID: id,
Content: payload.Content,
Created: time.Now().Unix(),
AutoDelete: config.Current.AutoDelete.Enabled,
Metadata: payload.Metadata,
}