logo

pleroma

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

instance_operation.ex (13144B)


  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. def rules_operation do
  44. %Operation{
  45. tags: ["Instance misc"],
  46. summary: "Retrieve list of instance rules",
  47. operationId: "InstanceController.rules",
  48. responses: %{
  49. 200 => Operation.response("Array of domains", "application/json", array_of_rules())
  50. }
  51. }
  52. end
  53. defp instance do
  54. %Schema{
  55. type: :object,
  56. properties: %{
  57. accounts: %Schema{
  58. type: :object,
  59. properties: %{
  60. max_featured_tags: %Schema{
  61. type: :integer,
  62. description: "The maximum number of featured tags allowed for each account."
  63. }
  64. }
  65. },
  66. uri: %Schema{type: :string, description: "The domain name of the instance"},
  67. title: %Schema{type: :string, description: "The title of the website"},
  68. description: %Schema{
  69. type: :string,
  70. description: "Admin-defined description of the Pleroma site"
  71. },
  72. version: %Schema{
  73. type: :string,
  74. description: "The version of Pleroma installed on the instance"
  75. },
  76. email: %Schema{
  77. type: :string,
  78. description: "An email that may be contacted for any inquiries",
  79. format: :email
  80. },
  81. urls: %Schema{
  82. type: :object,
  83. description: "URLs of interest for clients apps",
  84. properties: %{
  85. streaming_api: %Schema{
  86. type: :string,
  87. description: "Websockets address for push streaming"
  88. }
  89. }
  90. },
  91. stats: %Schema{
  92. type: :object,
  93. description: "Statistics about how much information the instance contains",
  94. properties: %{
  95. user_count: %Schema{
  96. type: :integer,
  97. description: "Users registered on this instance"
  98. },
  99. status_count: %Schema{
  100. type: :integer,
  101. description: "Statuses authored by users on instance"
  102. },
  103. domain_count: %Schema{
  104. type: :integer,
  105. description: "Domains federated with this instance"
  106. }
  107. }
  108. },
  109. thumbnail: %Schema{
  110. type: :string,
  111. description: "Banner image for the website",
  112. nullable: true
  113. },
  114. languages: %Schema{
  115. type: :array,
  116. items: %Schema{type: :string},
  117. description: "Primary languages of the website and its staff"
  118. },
  119. registrations: %Schema{type: :boolean, description: "Whether registrations are enabled"},
  120. # Extra (not present in Mastodon):
  121. max_toot_chars: %Schema{
  122. type: :integer,
  123. description: ": Posts character limit (CW/Subject included in the counter)"
  124. },
  125. poll_limits: %Schema{
  126. type: :object,
  127. description: "A map with poll limits for local polls",
  128. properties: %{
  129. max_options: %Schema{
  130. type: :integer,
  131. description: "Maximum number of options."
  132. },
  133. max_option_chars: %Schema{
  134. type: :integer,
  135. description: "Maximum number of characters per option."
  136. },
  137. min_expiration: %Schema{
  138. type: :integer,
  139. description: "Minimum expiration time (in seconds)."
  140. },
  141. max_expiration: %Schema{
  142. type: :integer,
  143. description: "Maximum expiration time (in seconds)."
  144. }
  145. }
  146. },
  147. upload_limit: %Schema{
  148. type: :integer,
  149. description: "File size limit of uploads (except for avatar, background, banner)"
  150. },
  151. avatar_upload_limit: %Schema{type: :integer, description: "The title of the website"},
  152. background_upload_limit: %Schema{type: :integer, description: "The title of the website"},
  153. banner_upload_limit: %Schema{type: :integer, description: "The title of the website"},
  154. background_image: %Schema{
  155. type: :string,
  156. format: :uri,
  157. description: "The background image for the website"
  158. }
  159. },
  160. example: %{
  161. "avatar_upload_limit" => 2_000_000,
  162. "background_upload_limit" => 4_000_000,
  163. "background_image" => "/static/image.png",
  164. "banner_upload_limit" => 4_000_000,
  165. "description" => "Pleroma: An efficient and flexible fediverse server",
  166. "email" => "lain@lain.com",
  167. "languages" => ["en"],
  168. "max_toot_chars" => 5000,
  169. "poll_limits" => %{
  170. "max_expiration" => 31_536_000,
  171. "max_option_chars" => 200,
  172. "max_options" => 20,
  173. "min_expiration" => 0
  174. },
  175. "registrations" => false,
  176. "stats" => %{
  177. "domain_count" => 2996,
  178. "status_count" => 15_802,
  179. "user_count" => 5
  180. },
  181. "thumbnail" => "https://lain.com/instance/thumbnail.jpeg",
  182. "title" => "lain.com",
  183. "upload_limit" => 16_000_000,
  184. "uri" => "https://lain.com",
  185. "urls" => %{
  186. "streaming_api" => "wss://lain.com"
  187. },
  188. "version" => "2.7.2 (compatible; Pleroma 2.0.50-536-g25eec6d7-develop)",
  189. "rules" => array_of_rules()
  190. }
  191. }
  192. end
  193. defp instance2 do
  194. %Schema{
  195. type: :object,
  196. properties: %{
  197. domain: %Schema{type: :string, description: "The domain name of the instance"},
  198. title: %Schema{type: :string, description: "The title of the website"},
  199. version: %Schema{
  200. type: :string,
  201. description: "The version of Pleroma installed on the instance"
  202. },
  203. source_url: %Schema{
  204. type: :string,
  205. description: "The version of Pleroma installed on the instance"
  206. },
  207. description: %Schema{
  208. type: :string,
  209. description: "Admin-defined description of the Pleroma site"
  210. },
  211. usage: %Schema{
  212. type: :object,
  213. description: "Instance usage statistics",
  214. properties: %{
  215. users: %Schema{
  216. type: :object,
  217. description: "User count statistics",
  218. properties: %{
  219. active_month: %Schema{
  220. type: :integer,
  221. description: "Monthly active users"
  222. }
  223. }
  224. }
  225. }
  226. },
  227. email: %Schema{
  228. type: :string,
  229. description: "An email that may be contacted for any inquiries",
  230. format: :email
  231. },
  232. urls: %Schema{
  233. type: :object,
  234. description: "URLs of interest for clients apps",
  235. properties: %{}
  236. },
  237. stats: %Schema{
  238. type: :object,
  239. description: "Statistics about how much information the instance contains",
  240. properties: %{
  241. user_count: %Schema{
  242. type: :integer,
  243. description: "Users registered on this instance"
  244. },
  245. status_count: %Schema{
  246. type: :integer,
  247. description: "Statuses authored by users on instance"
  248. },
  249. domain_count: %Schema{
  250. type: :integer,
  251. description: "Domains federated with this instance"
  252. }
  253. }
  254. },
  255. thumbnail: %Schema{
  256. type: :object,
  257. properties: %{
  258. url: %Schema{
  259. type: :string,
  260. description: "Banner image for the website",
  261. nullable: true
  262. }
  263. }
  264. },
  265. languages: %Schema{
  266. type: :array,
  267. items: %Schema{type: :string},
  268. description: "Primary languages of the website and its staff"
  269. },
  270. registrations: %Schema{
  271. type: :object,
  272. description: "Registrations-related configuration",
  273. properties: %{
  274. enabled: %Schema{
  275. type: :boolean,
  276. description: "Whether registrations are enabled"
  277. },
  278. approval_required: %Schema{
  279. type: :boolean,
  280. description: "Whether users need to be manually approved by admin"
  281. }
  282. }
  283. },
  284. configuration: %Schema{
  285. type: :object,
  286. description: "Instance configuration",
  287. properties: %{
  288. accounts: %Schema{
  289. type: :object,
  290. properties: %{
  291. max_featured_tags: %Schema{
  292. type: :integer,
  293. description: "The maximum number of featured tags allowed for each account."
  294. },
  295. max_pinned_statuses: %Schema{
  296. type: :integer,
  297. description: "The maximum number of pinned statuses for each account."
  298. }
  299. }
  300. },
  301. urls: %Schema{
  302. type: :object,
  303. properties: %{
  304. streaming: %Schema{
  305. type: :string,
  306. description: "Websockets address for push streaming"
  307. }
  308. }
  309. },
  310. statuses: %Schema{
  311. type: :object,
  312. description: "A map with poll limits for local statuses",
  313. properties: %{
  314. characters_reserved_per_url: %Schema{
  315. type: :integer,
  316. description:
  317. "Each URL in a status will be assumed to be exactly this many characters."
  318. },
  319. max_characters: %Schema{
  320. type: :integer,
  321. description: "Posts character limit (CW/Subject included in the counter)"
  322. },
  323. max_media_attachments: %Schema{
  324. type: :integer,
  325. description: "Media attachment limit"
  326. }
  327. }
  328. },
  329. media_attachments: %Schema{
  330. type: :object,
  331. description: "A map with poll limits for media attachments",
  332. properties: %{
  333. image_size_limit: %Schema{
  334. type: :integer,
  335. description: "File size limit of uploaded images"
  336. },
  337. video_size_limit: %Schema{
  338. type: :integer,
  339. description: "File size limit of uploaded videos"
  340. }
  341. }
  342. },
  343. polls: %Schema{
  344. type: :object,
  345. description: "A map with poll limits for local polls",
  346. properties: %{
  347. max_options: %Schema{
  348. type: :integer,
  349. description: "Maximum number of options."
  350. },
  351. max_characters_per_option: %Schema{
  352. type: :integer,
  353. description: "Maximum number of characters per option."
  354. },
  355. min_expiration: %Schema{
  356. type: :integer,
  357. description: "Minimum expiration time (in seconds)."
  358. },
  359. max_expiration: %Schema{
  360. type: :integer,
  361. description: "Maximum expiration time (in seconds)."
  362. }
  363. }
  364. }
  365. }
  366. }
  367. }
  368. }
  369. end
  370. defp array_of_domains do
  371. %Schema{
  372. type: :array,
  373. items: %Schema{type: :string},
  374. example: ["pleroma.site", "lain.com", "bikeshed.party"]
  375. }
  376. end
  377. defp array_of_rules do
  378. %Schema{
  379. type: :array,
  380. items: %Schema{
  381. type: :object,
  382. properties: %{
  383. id: %Schema{type: :string},
  384. text: %Schema{type: :string},
  385. hint: %Schema{type: :string}
  386. }
  387. }
  388. }
  389. end
  390. end