Done Automatic file cleanup in "Shares"

Discussion in 'Feature Requests' started by Ognyan LIpnichanski, Aug 11, 2022.

?

Do you find this idea useful:

  1. Yes

    4 vote(s)
    100.0%
  2. No

    0 vote(s)
    0.0%
  1. Ognyan LIpnichanski

    Ognyan LIpnichanski New Member

    Joined:
    Aug 11, 2022
    Messages:
    2
    Likes Received:
    0
    Dear Developers,

    I just want to ask if it's possible to extend the functionality of "Shares" by adding a new option for how many days to keep files there before deleting them. I believe we can do that with a shell script on the server, but it will be more convenient to do this as simple as a single option in the web interface of the Edit Share page.

    I have attached a demo of the UI as i imagined it.
     

    Attached Files:

  2. Ognyan LIpnichanski

    Ognyan LIpnichanski New Member

    Joined:
    Aug 11, 2022
    Messages:
    2
    Likes Received:
    0
    So, i have learned from David Gnojek, that they are planning the following feature in the next major release:

    According to the Shares. Exactly the request you described is not planned on active files because Shares are permanent storage. But this function is planned on files in the trash.
    In a next major version we will add a function which will delete the files from the trash automatically after some time.
    This should solve the space problems where users sometimes move the files in the trash where still occupied the disk space until somebody remove them manually.


    My proposal is to have both. There can be two options in the Edit Share dialog where you can specify:
    1. How many days to keep the files after they have been uploaded and then moved to Trash.
    2. How many days to keep the files in the Trash before deleted permanently.
     
  3. Don Shifflett

    Don Shifflett New Member

    Joined:
    Jan 10, 2025
    Messages:
    2
    Likes Received:
    0
    I'm bumping this request. We are looking for a way to set a default number of days for data in Shares to be automatically deleted. We would like this value to be set by the administrator for all Shares.
     
  4. Aldo

    Aldo New Member

    Joined:
    Jul 21, 2021
    Messages:
    9
    Likes Received:
    0
    I also want this feature! I am currently accomplishing this with a Powershell script on a scheduled task that uses the API to get a list of files then delete any older than X days. Lemme clean it up and I'll post it.
     
  5. David

    David Administrator
    Staff Member

    Joined:
    Dec 1, 2015
    Messages:
    827
    Likes Received:
    33
    Since 4.1.5x beta releases it's possible to configure in Shares that the deleted files in trash can be automatically removed after N days.
     
  6. Don Shifflett

    Don Shifflett New Member

    Joined:
    Jan 10, 2025
    Messages:
    2
    Likes Received:
    0
    Aldo, it would be awesome if you could post the Powershell script! Thanks!
     
  7. Aldo

    Aldo New Member

    Joined:
    Jul 21, 2021
    Messages:
    9
    Likes Received:
    0
    This script requires Powershell Core (version 7+)

    $expiration = '-30' # any files older than 30 day will be deleted
    $liquidfilesSharesUrl = 'https://<liquidfiles server URL>/shares'
    $api_key = '<API Key>' #We setup a Service account in LF to get an API key
    $api_password = ConvertTo-SecureString -String 'x' -AsPlainText -Force

    #You can put in a list of the shares as json
    $share_list = @"
    {
    "shares": [
    {
    "id": "customer-files",
    "name": "Customer Files",
    "description": null,
    "access": "write",
    "view_log": false,
    "revisions": 1,
    "quota": null,
    "created_at": "2023-04-14T00:57:26.696Z",
    "updated_at": "2023-04-15T13:36:23.019Z"
    }
    ]
    }
    "@ | ConvertFrom-Json | Select-Object -ExpandProperty shares

    #region Get folder list
    foreach ($share in $share_list) {
    try {
    $shares_api_response=$null
    $api_folders_call = @{
    Method = 'GET'
    Uri = "$liquidfilesUrl/$($share.id)/"
    Authentication = 'Basic'
    Credential = [PSCredential]::new($api_key,$api_password)
    ContentType = 'application/json'
    Headers = @{Accept = 'application/json'}
    ErrorAction = 'Stop'
    }
    $shares_api_response = Invoke-RestMethod @api_folders_call
    if(!$shares_api_response) {Throw "API call for $($share.id) failed."}
    $folders_list = $shares_api_response.share.root_folder.folders
    #region Get files list
    foreach ($folder in $folders_list){
    $api_files_call = @{
    Method = 'GET'
    Uri = '{0}/{1}/folders/{2}' -f $liquidfilesSharesUrl,$share.id,$folder.id
    Authentication = 'Basic'
    Credential = [PSCredential]::new($api_key,$api_password)
    ContentType = 'application/json'
    Headers = @{Accept = 'application/json'}
    }
    $files = Invoke-RestMethod @api_files_call
    $files_to_delete = $files.folder.files |
    Where-Object{$_.created_at -lt (get-date).adddays($expiration) -and $_.deleted -ne $true}
    foreach ($file in $files_to_delete){
    $delete_api_call = @{
    Method = 'DELETE'
    Uri = '{0}/{1}/folders/{2}/files/{3}' -f $liquidfilesSharesUrl,$share.id,$folder.id,$file.id
    Authentication = 'Basic'
    Credential = [PSCredential]::new($api_key,$api_password)
    ContentType = 'application/json'
    Headers = @{Accept = 'application/json'}
    Verbose = $true
    }
    Write-Output "Deleting $($file.id) file created at $($file.created_at)"
    Invoke-RestMethod @delete_api_call
    } # end of foreach ($file in $files_to_delete)
    } # end of foreach ($folder in $folders_list)
    #endregion Get files list
    }
    catch {"Error: $($error[0].exception.message)"}
    } # end of foreach ($share in $share_list)
     
  8. Aldo

    Aldo New Member

    Joined:
    Jul 21, 2021
    Messages:
    9
    Likes Received:
    0
    If you need to get the list of shares you can use this

    $liquidfilesSharesUrl = 'https://<liquidfiles server URL>/shares'
    $api_key = '<API Key>' #We setup a Service account in LF to get an API key
    $api_password = ConvertTo-SecureString -String 'x' -AsPlainText -Force
    $credentials = [System.Management.Automation.PSCredential]::new($api_key,$api_password)

    $shareListApiResponse = Invoke-RestMethod -Method get -uri $liquidfilesSharesUrl -Authentication Basic -ContentType 'application/json' -Credential $credentials
    $shares = $apiResponse.shares.id
    foreach ($share in $shares){
    $shareApiResponse = Invoke-RestMethod -Method get -uri "$liquidfilesSharesUrl/$share" -Authentication Basic -ContentType 'application/json' -Credential $credentials | Select-Object Share
    $shareApiResponse.share.root_folder | Select-Object share_id,id
    }
     
    #8 Aldo, Aug 8, 2025 at 6:37 AM
    Last edited: Aug 8, 2025 at 6:44 AM

Share This Page