Advertisement
bahman

Lemmy - Content Categorisation Extension API

Oct 11th, 2023 (edited)
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | Source Code | 0 0
  1. ####################################################################################################
  2. # Content Categorisation (CCat) API
  3. #
  4. # Consumed by lemmy-core
  5. # Provided by CCat extensions
  6. #
  7. # Side-effect free. There will be no modification to content/data.
  8. # Only produces stats about the content to help w/ mod operations.
  9. ####################################################################################################
  10.  
  11. ######
  12. # Expected to be slow.
  13. #
  14. # Run preferably only once for each content.
  15. ######
  16. POST /ccat/cateorise/:contentId
  17.  
  18. PAYLOAD:
  19. {
  20. "additionContext": { ... }
  21. }
  22.  
  23. RESPONSE:
  24. {
  25. "contentId": :contentId,
  26. "categories": {
  27. "category_X": {
  28. "score": 80,
  29. "additionalData": { ... }
  30. }
  31. "cat_Y": {
  32. "score": 3,
  33. "additionalData": { ... }
  34. }
  35. }
  36. }
  37.  
  38. ######
  39. # Expected to be fast.
  40. #
  41. # Run many times per content. Preferably returns the result produced and cached
  42. # in the POST endpoint.
  43. #####
  44. GET /ccat/categories/:contentId
  45.  
  46. RESPONSE:
  47. {
  48. "contentId": :contentId,
  49. "categories": {
  50. "category_X": {
  51. "score": 80,
  52. "additionalData": { ... }
  53. }
  54. "cat_Y": {
  55. "score": 3,
  56. "additionalData": { ... }
  57. }
  58. }
  59. }
  60.  
  61.  
  62. ####################################################################################################
  63. # Somewhere in lemmy-core
  64. ####################################################################################################
  65.  
  66. after_store_content(content) {
  67. ccat_extensions = instance.get_active_ccat_extensions()
  68. ccat_result = {};
  69. for each cce in ccat_extensions {
  70. ccat_result += http.post(cce, content.id, ...)
  71. }
  72. }
  73.  
  74. ####################################################################################################
  75. # Somewhere in lemmy-ui
  76. ####################################################################################################
  77.  
  78. load_content_for_mod_review(content, ccat_extensions) {
  79. for each cce in ccat_extensions {
  80. ccat_result = http.get(cce, content.id)
  81. display_ccat_result_next_to_content(ccat_result, content.id)
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement