logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

instance_operation.ex (11524B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ApiSpec.InstanceOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. def open_api_operation(action) do
  8. operation = String.to_existing_atom("#{action}_operation")
  9. apply(__MODULE__, operation, [])
  10. end
  11. def show_operation do
  12. %Operation{
  13. tags: ["Instance misc"],
  14. summary: "Retrieve instance information",
  15. description: "Information about the server",
  16. operationId: "InstanceController.show",
  17. responses: %{
  18. 200 => Operation.response("Instance", "application/json", instance())
  19. }
  20. }
  21. end
  22. def show2_operation do
  23. %Operation{
  24. tags: ["Instance misc"],
  25. summary: "Retrieve instance information",
  26. description: "Information about the server",
  27. operationId: "InstanceController.show2",
  28. responses: %{
  29. 200 => Operation.response("Instance", "application/json", instance2())
  30. }
  31. }
  32. end
  33. def peers_operation do
  34. %Operation{
  35. tags: ["Instance misc"],
  36. summary: "Retrieve list of known instances",
  37. operationId: "InstanceController.peers",
  38. responses: %{
  39. 200 => Operation.response("Array of domains", "application/json", array_of_domains())
  40. }
  41. }
  42. end
  43. defp instance do
  44. %Schema{
  45. type: :object,
  46. properties: %{
  47. uri: %Schema{type: :string, description: "The domain name of the instance"},
  48. title: %Schema{type: :string, description: "The title of the website"},
  49. description: %Schema{
  50. type: :string,
  51. description: "Admin-defined description of the Pleroma site"
  52. },
  53. version: %Schema{
  54. type: :string,
  55. description: "The version of Pleroma installed on the instance"
  56. },
  57. email: %Schema{
  58. type: :string,
  59. description: "An email that may be contacted for any inquiries",
  60. format: :email
  61. },
  62. urls: %Schema{
  63. type: :object,
  64. description: "URLs of interest for clients apps",
  65. properties: %{
  66. streaming_api: %Schema{
  67. type: :string,
  68. description: "Websockets address for push streaming"
  69. }
  70. }
  71. },
  72. stats: %Schema{
  73. type: :object,
  74. description: "Statistics about how much information the instance contains",
  75. properties: %{
  76. user_count: %Schema{
  77. type: :integer,
  78. description: "Users registered on this instance"
  79. },
  80. status_count: %Schema{
  81. type: :integer,
  82. description: "Statuses authored by users on instance"
  83. },
  84. domain_count: %Schema{
  85. type: :integer,
  86. description: "Domains federated with this instance"
  87. }
  88. }
  89. },
  90. thumbnail: %Schema{
  91. type: :string,
  92. description: "Banner image for the website",
  93. nullable: true
  94. },
  95. languages: %Schema{
  96. type: :array,
  97. items: %Schema{type: :string},
  98. description: "Primary languages of the website and its staff"
  99. },
  100. registrations: %Schema{type: :boolean, description: "Whether registrations are enabled"},
  101. # Extra (not present in Mastodon):
  102. max_toot_chars: %Schema{
  103. type: :integer,
  104. description: ": Posts character limit (CW/Subject included in the counter)"
  105. },
  106. poll_limits: %Schema{
  107. type: :object,
  108. description: "A map with poll limits for local polls",
  109. properties: %{
  110. max_options: %Schema{
  111. type: :integer,
  112. description: "Maximum number of options."
  113. },
  114. max_option_chars: %Schema{
  115. type: :integer,
  116. description: "Maximum number of characters per option."
  117. },
  118. min_expiration: %Schema{
  119. type: :integer,
  120. description: "Minimum expiration time (in seconds)."
  121. },
  122. max_expiration: %Schema{
  123. type: :integer,
  124. description: "Maximum expiration time (in seconds)."
  125. }
  126. }
  127. },
  128. upload_limit: %Schema{
  129. type: :integer,
  130. description: "File size limit of uploads (except for avatar, background, banner)"
  131. },
  132. avatar_upload_limit: %Schema{type: :integer, description: "The title of the website"},
  133. background_upload_limit: %Schema{type: :integer, description: "The title of the website"},
  134. banner_upload_limit: %Schema{type: :integer, description: "The title of the website"},
  135. background_image: %Schema{
  136. type: :string,
  137. format: :uri,
  138. description: "The background image for the website"
  139. }
  140. },
  141. example: %{
  142. "avatar_upload_limit" => 2_000_000,
  143. "background_upload_limit" => 4_000_000,
  144. "background_image" => "/static/image.png",
  145. "banner_upload_limit" => 4_000_000,
  146. "description" => "Pleroma: An efficient and flexible fediverse server",
  147. "email" => "lain@lain.com",
  148. "languages" => ["en"],
  149. "max_toot_chars" => 5000,
  150. "poll_limits" => %{
  151. "max_expiration" => 31_536_000,
  152. "max_option_chars" => 200,
  153. "max_options" => 20,
  154. "min_expiration" => 0
  155. },
  156. "registrations" => false,
  157. "stats" => %{
  158. "domain_count" => 2996,
  159. "status_count" => 15_802,
  160. "user_count" => 5
  161. },
  162. "thumbnail" => "https://lain.com/instance/thumbnail.jpeg",
  163. "title" => "lain.com",
  164. "upload_limit" => 16_000_000,
  165. "uri" => "https://lain.com",
  166. "urls" => %{
  167. "streaming_api" => "wss://lain.com"
  168. },
  169. "version" => "2.7.2 (compatible; Pleroma 2.0.50-536-g25eec6d7-develop)"
  170. }
  171. }
  172. end
  173. defp instance2 do
  174. %Schema{
  175. type: :object,
  176. properties: %{
  177. domain: %Schema{type: :string, description: "The domain name of the instance"},
  178. title: %Schema{type: :string, description: "The title of the website"},
  179. version: %Schema{
  180. type: :string,
  181. description: "The version of Pleroma installed on the instance"
  182. },
  183. source_url: %Schema{
  184. type: :string,
  185. description: "The version of Pleroma installed on the instance"
  186. },
  187. description: %Schema{
  188. type: :string,
  189. description: "Admin-defined description of the Pleroma site"
  190. },
  191. usage: %Schema{
  192. type: :object,
  193. description: "Instance usage statistics",
  194. properties: %{
  195. users: %Schema{
  196. type: :object,
  197. description: "User count statistics",
  198. properties: %{
  199. active_month: %Schema{
  200. type: :integer,
  201. description: "Monthly active users"
  202. }
  203. }
  204. }
  205. }
  206. },
  207. email: %Schema{
  208. type: :string,
  209. description: "An email that may be contacted for any inquiries",
  210. format: :email
  211. },
  212. urls: %Schema{
  213. type: :object,
  214. description: "URLs of interest for clients apps",
  215. properties: %{}
  216. },
  217. stats: %Schema{
  218. type: :object,
  219. description: "Statistics about how much information the instance contains",
  220. properties: %{
  221. user_count: %Schema{
  222. type: :integer,
  223. description: "Users registered on this instance"
  224. },
  225. status_count: %Schema{
  226. type: :integer,
  227. description: "Statuses authored by users on instance"
  228. },
  229. domain_count: %Schema{
  230. type: :integer,
  231. description: "Domains federated with this instance"
  232. }
  233. }
  234. },
  235. thumbnail: %Schema{
  236. type: :object,
  237. properties: %{
  238. url: %Schema{
  239. type: :string,
  240. description: "Banner image for the website",
  241. nullable: true
  242. }
  243. }
  244. },
  245. languages: %Schema{
  246. type: :array,
  247. items: %Schema{type: :string},
  248. description: "Primary languages of the website and its staff"
  249. },
  250. registrations: %Schema{
  251. type: :object,
  252. description: "Registrations-related configuration",
  253. properties: %{
  254. enabled: %Schema{
  255. type: :boolean,
  256. description: "Whether registrations are enabled"
  257. },
  258. approval_required: %Schema{
  259. type: :boolean,
  260. description: "Whether users need to be manually approved by admin"
  261. }
  262. }
  263. },
  264. configuration: %Schema{
  265. type: :object,
  266. description: "Instance configuration",
  267. properties: %{
  268. urls: %Schema{
  269. type: :object,
  270. properties: %{
  271. streaming: %Schema{
  272. type: :string,
  273. description: "Websockets address for push streaming"
  274. }
  275. }
  276. },
  277. statuses: %Schema{
  278. type: :object,
  279. description: "A map with poll limits for local statuses",
  280. properties: %{
  281. max_characters: %Schema{
  282. type: :integer,
  283. description: "Posts character limit (CW/Subject included in the counter)"
  284. },
  285. max_media_attachments: %Schema{
  286. type: :integer,
  287. description: "Media attachment limit"
  288. }
  289. }
  290. },
  291. media_attachments: %Schema{
  292. type: :object,
  293. description: "A map with poll limits for media attachments",
  294. properties: %{
  295. image_size_limit: %Schema{
  296. type: :integer,
  297. description: "File size limit of uploaded images"
  298. },
  299. video_size_limit: %Schema{
  300. type: :integer,
  301. description: "File size limit of uploaded videos"
  302. }
  303. }
  304. },
  305. polls: %Schema{
  306. type: :object,
  307. description: "A map with poll limits for local polls",
  308. properties: %{
  309. max_options: %Schema{
  310. type: :integer,
  311. description: "Maximum number of options."
  312. },
  313. max_characters_per_option: %Schema{
  314. type: :integer,
  315. description: "Maximum number of characters per option."
  316. },
  317. min_expiration: %Schema{
  318. type: :integer,
  319. description: "Minimum expiration time (in seconds)."
  320. },
  321. max_expiration: %Schema{
  322. type: :integer,
  323. description: "Maximum expiration time (in seconds)."
  324. }
  325. }
  326. }
  327. }
  328. }
  329. }
  330. }
  331. end
  332. defp array_of_domains do
  333. %Schema{
  334. type: :array,
  335. items: %Schema{type: :string},
  336. example: ["pleroma.site", "lain.com", "bikeshed.party"]
  337. }
  338. end
  339. end