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)
|
* `modificationToken` (string)
|
||||||
* The token used to authenticate with paste-specific secured endpoints; stored hashed and only returned on initial paste creation
|
* The token used to authenticate with paste-specific secured endpoints; stored hashed and only returned on initial paste creation
|
||||||
* `created` (int64; UNIX timestamp)
|
* `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)
|
* `metadata` (key-value store)
|
||||||
* Different frontends may store simple key-value metadata pairs on pastes to enable specific functionality (for example clientside encryption)
|
* 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",
|
"id": "paste_id",
|
||||||
"content": "paste_content",
|
"content": "paste_content",
|
||||||
"created": 0000000000,
|
"created": 0000000000,
|
||||||
"autoDelete": false,
|
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -122,7 +119,6 @@ POST /api/v2/pastes
|
|||||||
"content": "paste_content",
|
"content": "paste_content",
|
||||||
"modificationToken": "raw_modification_token",
|
"modificationToken": "raw_modification_token",
|
||||||
"created": 0000000000,
|
"created": 0000000000,
|
||||||
"autoDelete": false,
|
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -149,7 +145,6 @@ PATCH /api/v2/pastes/{paste_id}
|
|||||||
"id": "paste_id",
|
"id": "paste_id",
|
||||||
"content": "new_paste_content",
|
"content": "new_paste_content",
|
||||||
"created": 0000000000,
|
"created": 0000000000,
|
||||||
"autoDelete": false,
|
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -13,7 +13,6 @@ type Paste struct {
|
|||||||
DeletionToken string `json:"deletionToken,omitempty" bson:"deletionToken"` // Required for legacy paste storage support
|
DeletionToken string `json:"deletionToken,omitempty" bson:"deletionToken"` // Required for legacy paste storage support
|
||||||
ModificationToken string `json:"modificationToken,omitempty" bson:"modificationToken"`
|
ModificationToken string `json:"modificationToken,omitempty" bson:"modificationToken"`
|
||||||
Created int64 `json:"created" bson:"created"`
|
Created int64 `json:"created" bson:"created"`
|
||||||
AutoDelete bool `json:"autoDelete" bson:"autoDelete"`
|
|
||||||
Metadata map[string]interface{} `json:"metadata" bson:"metadata"`
|
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
|
// Delete the paste if it is expired
|
||||||
lifetime := config.Current.AutoDelete.Lifetime
|
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)
|
err = driver.Delete(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return deleted, err
|
return deleted, err
|
||||||
|
@ -159,7 +159,7 @@ func (driver *MongoDBDriver) Cleanup() (int, error) {
|
|||||||
|
|
||||||
// Delete the paste if it is expired
|
// Delete the paste if it is expired
|
||||||
lifetime := config.Current.AutoDelete.Lifetime
|
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)
|
err = driver.Delete(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
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)
|
row := driver.pool.QueryRow(context.Background(), query, id)
|
||||||
|
|
||||||
paste := new(shared.Paste)
|
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) {
|
if errors.Is(err, pgx.ErrNoRows) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@ -94,17 +94,16 @@ func (driver *PostgresDriver) Get(id string) (*shared.Paste, error) {
|
|||||||
// Save saves a paste
|
// Save saves a paste
|
||||||
func (driver *PostgresDriver) Save(paste *shared.Paste) error {
|
func (driver *PostgresDriver) Save(paste *shared.Paste) error {
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO pastes (id, content, "modificationToken", created, "autoDelete", metadata)
|
INSERT INTO pastes (id, content, "modificationToken", created, metadata)
|
||||||
VALUES ($1, $2, $3, $4, $5, $6)
|
VALUES ($1, $2, $3, $4, $5)
|
||||||
ON CONFLICT (id) DO UPDATE
|
ON CONFLICT (id) DO UPDATE
|
||||||
SET content = excluded.content,
|
SET content = excluded.content,
|
||||||
"modificationToken" = excluded."modificationToken",
|
"modificationToken" = excluded."modificationToken",
|
||||||
created = excluded.created,
|
created = excluded.created,
|
||||||
"autoDelete" = excluded."autoDelete",
|
|
||||||
metadata = excluded.metadata
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +117,7 @@ func (driver *PostgresDriver) Delete(id string) error {
|
|||||||
|
|
||||||
// Cleanup cleans up the expired pastes
|
// Cleanup cleans up the expired pastes
|
||||||
func (driver *PostgresDriver) Cleanup() (int, error) {
|
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())
|
tag, err := driver.pool.Exec(context.Background(), query, time.Now().Add(-config.Current.AutoDelete.Lifetime).Unix())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -124,7 +124,7 @@ func (driver *S3Driver) Cleanup() (int, error) {
|
|||||||
|
|
||||||
// Delete the paste if it is expired
|
// Delete the paste if it is expired
|
||||||
lifetime := config.Current.AutoDelete.Lifetime
|
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)
|
err = driver.Delete(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
@ -44,10 +44,9 @@ func HastebinSupportHandler(ctx *fasthttp.RequestCtx) {
|
|||||||
|
|
||||||
// Create the paste object
|
// Create the paste object
|
||||||
paste := &shared.Paste{
|
paste := &shared.Paste{
|
||||||
ID: id,
|
ID: id,
|
||||||
Content: content,
|
Content: content,
|
||||||
Created: time.Now().Unix(),
|
Created: time.Now().Unix(),
|
||||||
AutoDelete: config.Current.AutoDelete.Enabled,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a modification token
|
// Set a modification token
|
||||||
|
@ -7,7 +7,6 @@ type legacyPaste struct {
|
|||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
DeletionToken string `json:"deletionToken,omitempty"`
|
DeletionToken string `json:"deletionToken,omitempty"`
|
||||||
Created int64 `json:"created"`
|
Created int64 `json:"created"`
|
||||||
AutoDelete bool `json:"autoDelete"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func legacyFromModern(paste *shared.Paste) *legacyPaste {
|
func legacyFromModern(paste *shared.Paste) *legacyPaste {
|
||||||
@ -21,6 +20,5 @@ func legacyFromModern(paste *shared.Paste) *legacyPaste {
|
|||||||
Content: paste.Content,
|
Content: paste.Content,
|
||||||
DeletionToken: deletionToken,
|
DeletionToken: deletionToken,
|
||||||
Created: paste.Created,
|
Created: paste.Created,
|
||||||
AutoDelete: paste.AutoDelete,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,10 +86,9 @@ func v1PostPaste(ctx *fasthttp.RequestCtx) {
|
|||||||
|
|
||||||
// Create the paste object
|
// Create the paste object
|
||||||
paste := &shared.Paste{
|
paste := &shared.Paste{
|
||||||
ID: id,
|
ID: id,
|
||||||
Content: values["content"],
|
Content: values["content"],
|
||||||
Created: time.Now().Unix(),
|
Created: time.Now().Unix(),
|
||||||
AutoDelete: config.Current.AutoDelete.Enabled,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a modification token
|
// Set a modification token
|
||||||
|
@ -136,11 +136,10 @@ func endpointCreatePaste(ctx *fasthttp.RequestCtx) {
|
|||||||
payload.Metadata = map[string]interface{}{}
|
payload.Metadata = map[string]interface{}{}
|
||||||
}
|
}
|
||||||
paste := &shared.Paste{
|
paste := &shared.Paste{
|
||||||
ID: id,
|
ID: id,
|
||||||
Content: payload.Content,
|
Content: payload.Content,
|
||||||
Created: time.Now().Unix(),
|
Created: time.Now().Unix(),
|
||||||
AutoDelete: config.Current.AutoDelete.Enabled,
|
Metadata: payload.Metadata,
|
||||||
Metadata: payload.Metadata,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new modification token if enabled
|
// Create a new modification token if enabled
|
||||||
|
Loading…
Reference in New Issue
Block a user