Last active
March 22, 2021 01:54
-
-
Save Erisa/5de647fcc9e5472846f38e12cb1d027f to your computer and use it in GitHub Desktop.
Restore everything from trash in seafile
This file contains hidden or 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
# frozen_string_literal: true | |
require 'json' | |
require 'net/http' | |
libs = [ | |
"aa3ffa6f-61d3-4cda-bf7d-89a856068fc3", | |
"563aa837-4865-4e4e-b0aa-6333c2634c64", | |
"385275da-c656-4f2f-918a-d4190828ae20", | |
'c50d9d60-5478-4c27-89d5-b3c6d1708438', | |
'aa3ffa6f-61d3-4cda-bf7d-89a856068fc3', | |
'36228103-e03f-4f4e-8b6b-62356c507c6b', | |
'bb0abf65-73ba-428b-8582-a95ff20753ff' | |
] | |
cookie = 'sfcsrftoken=aaaaaaaaaaaaaaaa; sessionid=aaaaaaaaaaa; __cfduid=aaaaaaaaaaaaaaaaaa' | |
csrf_token = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' | |
libs.each do |lib| | |
json = `curl -s -H "Cookie: #{cookie}" 'https://erisa.cloud/api/v2.1/repos/#{lib}/trash/?path=%2F'` | |
hash = JSON.parse(json) | |
loop do | |
hash['data'].each do |value| | |
# p value["parent_dir"] + value["obj_name"] | |
uri = URI.parse('https://erisa.cloud') | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
request = Net::HTTP::Put.new("/api2/repos/#{lib}/file/revert/") | |
request.add_field('Content-Type', 'application/json') | |
request.add_field('Cookie', cookie) | |
request.add_field('X-CSRFToken', csrf_token) | |
request.body = { | |
'commit_id' => value['commit_id'], | |
'p' => value['parent_dir'] + value['obj_name'] | |
}.to_json | |
p value['parent_dir'] + value['obj_name'] | |
response = http.request(request) | |
p response | |
end | |
p hash['more'] | |
p hash['scan_stat'] | |
if hash['more'] == true | |
json = `curl -s -H "Cookie: #{cookie}" 'https://erisa.cloud/api/v2.1/repos/#{lib}/trash/?path=%2F&scan_stat=#{hash['scan_stat']}'` | |
hash = JSON.parse(json) | |
else | |
break | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment