bookserie.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package libamuse
  2. import (
  3. "notabug.org/apiote/amuse/wikidata"
  4. "notabug.org/apiote/amuse/accounts"
  5. "strings"
  6. "notabug.org/apiote/gott"
  7. )
  8. func getBookSerie(args ...interface{}) (interface{}, error) {
  9. data := args[0].(*RequestData)
  10. result := args[1].(*Result)
  11. languages := result.languages
  12. bookSerie, err := wikidata.GetBookSerie(data.id, languages[0].String(), data.connection)
  13. result.result = bookSerie
  14. return gott.Tuple(args), err
  15. }
  16. func getOrdinals(args ...interface{}) (interface{}, error) {
  17. data := args[0].(*RequestData)
  18. result := args[1].(*Result)
  19. bookSerie := result.result.(*wikidata.BookSerie)
  20. _, err := wikidata.GetBookSerieOrdinals(data.id, bookSerie, data.connection)
  21. return gott.Tuple(args), err
  22. }
  23. func getCovers(args ...interface{}) (interface{}, error) {
  24. data := args[0].(*RequestData)
  25. result := args[1].(*Result)
  26. bookSerie := result.result.(*wikidata.BookSerie)
  27. languages := result.languages
  28. for i, part := range bookSerie.SortedParts {
  29. partId := strings.Replace(part.Uri, "/books/", "", 1)
  30. cover, err := wikidata.GetCover(partId, languages[0].String(), data.connection)
  31. if err != nil {
  32. return gott.Tuple(args), err
  33. }
  34. bookSerie.SortedParts[i].Cover = cover
  35. }
  36. return gott.Tuple(args), nil
  37. }
  38. func renderBookSerie(args ...interface{}) interface{} {
  39. result := args[1].(*Result)
  40. bookSerie := result.result.(*wikidata.BookSerie)
  41. result.page = result.renderer.RenderBookSerie(*bookSerie, result.languages)
  42. return gott.Tuple(args)
  43. }
  44. func ShowBookSerie(id, language, mimetype string, auth accounts.Authentication) (string, error) {
  45. auth.Necessary = false
  46. r, err := gott.
  47. NewResult(gott.Tuple{&RequestData{id: id, language: language, mimetype: mimetype, auth: auth}, &Result{}}).
  48. Bind(parseLanguage).
  49. Bind(verifyToken).
  50. Bind(getBookSerie).
  51. Bind(getOrdinals).
  52. Bind(getDescription).
  53. Bind(getCovers).
  54. Bind(createRenderer).
  55. Map(renderBookSerie).
  56. Finish()
  57. if err != nil {
  58. return "", err
  59. } else {
  60. return r.(gott.Tuple)[1].(*Result).page, nil
  61. }
  62. }