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:
parent
4f3b5b193b
commit
1818fac196
5
API.md
5
API.md
@ -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": {},
|
||||
}
|
||||
```
|
||||
|
@ -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"`
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -0,0 +1,5 @@
|
||||
begin;
|
||||
|
||||
alter table if exists "pastes" add column "autoDelete" boolean;
|
||||
|
||||
commit;
|
@ -0,0 +1,5 @@
|
||||
begin;
|
||||
|
||||
alter table if exists "pastes" drop column "autoDelete";
|
||||
|
||||
commit;
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -44,10 +44,9 @@ func HastebinSupportHandler(ctx *fasthttp.RequestCtx) {
|
||||
|
||||
// Create the paste object
|
||||
paste := &shared.Paste{
|
||||
ID: id,
|
||||
Content: content,
|
||||
Created: time.Now().Unix(),
|
||||
AutoDelete: config.Current.AutoDelete.Enabled,
|
||||
ID: id,
|
||||
Content: content,
|
||||
Created: time.Now().Unix(),
|
||||
}
|
||||
|
||||
// Set a modification token
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -86,10 +86,9 @@ func v1PostPaste(ctx *fasthttp.RequestCtx) {
|
||||
|
||||
// Create the paste object
|
||||
paste := &shared.Paste{
|
||||
ID: id,
|
||||
Content: values["content"],
|
||||
Created: time.Now().Unix(),
|
||||
AutoDelete: config.Current.AutoDelete.Enabled,
|
||||
ID: id,
|
||||
Content: values["content"],
|
||||
Created: time.Now().Unix(),
|
||||
}
|
||||
|
||||
// Set a modification token
|
||||
|
@ -136,11 +136,10 @@ func endpointCreatePaste(ctx *fasthttp.RequestCtx) {
|
||||
payload.Metadata = map[string]interface{}{}
|
||||
}
|
||||
paste := &shared.Paste{
|
||||
ID: id,
|
||||
Content: payload.Content,
|
||||
Created: time.Now().Unix(),
|
||||
AutoDelete: config.Current.AutoDelete.Enabled,
|
||||
Metadata: payload.Metadata,
|
||||
ID: id,
|
||||
Content: payload.Content,
|
||||
Created: time.Now().Unix(),
|
||||
Metadata: payload.Metadata,
|
||||
}
|
||||
|
||||
// Create a new modification token if enabled
|
||||
|
Loading…
Reference in New Issue
Block a user