-
Notifications
You must be signed in to change notification settings - Fork 2
/
provider.rb
55 lines (49 loc) · 1.58 KB
/
provider.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require "httparty"
require_relative "config"
require_relative "constants"
require_relative "logger"
require_relative "providers/pleroma"
require_relative "providers/mastodon"
require_relative "providers/misskey"
module FediEbooks
class Provider
@logger = FediEbooks::Logger.instance
def self.select_provider
case get_software
when FediEbooks::Constants::InstanceType::PLEROMA
FediEbooks::PleromaProvider.new
when FediEbooks::Constants::InstanceType::MASTODON
FediEbooks::MastodonProvider.new
when FediEbooks::Constants::InstanceType::MISSKEY
FediEbooks::MisskeyProvider.new
else
@logger.log("Invalid instance type!")
exit(1)
end
end
def self.get_software
begin
headers = { "Content-Type": "application/json" }
version = HTTParty.get("#{FediEbooks::Config.instance_url}/api/v1/instance",
headers: headers)["version"]
version = version.downcase
if version.include?("pleroma") || version.include?("akkoma")
return FediEbooks::Constants::InstanceType::PLEROMA
else
return FediEbooks::Constants::InstanceType::MASTODON
end
rescue
# Ignored
end
begin
headers = { "Content-Type": "application/json" }
unless HTTParty.post("#{FediEbooks::Config.instance_url}/api/meta",
headers: headers)["driveCapacityPerLocalUserMb"].nil?
FediEbooks::Constants::InstanceType::MISSKEY
end
rescue
# Ignored
end
end
end
end