api.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. export const getEndpoint = () => {
  2. const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
  3. if (isDevDeployment() && endpoint) {
  4. return endpoint;
  5. }
  6. return 'https://api.ente.io';
  7. };
  8. export const getFileURL = (id: number) => {
  9. const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
  10. if (isDevDeployment() && endpoint) {
  11. return `${endpoint}/files/download/${id}`;
  12. }
  13. return `https://files.ente.io/?fileID=${id}`;
  14. };
  15. export const getPublicCollectionFileURL = (id: number) => {
  16. const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
  17. if (isDevDeployment() && endpoint) {
  18. return `${endpoint}/public-collection/files/download/${id}`;
  19. }
  20. return `https://public-albums.ente.io/download/?fileID=${id}`;
  21. };
  22. export const getThumbnailURL = (id: number) => {
  23. const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
  24. if (isDevDeployment() && endpoint) {
  25. return `${endpoint}/files/preview/${id}`;
  26. }
  27. return `https://thumbnails.ente.io/?fileID=${id}`;
  28. };
  29. export const getPublicCollectionThumbnailURL = (id: number) => {
  30. const endpoint = process.env.NEXT_PUBLIC_ENTE_ENDPOINT;
  31. if (isDevDeployment() && endpoint) {
  32. return `${endpoint}/public-collection/files/preview/${id}`;
  33. }
  34. return `https://public-albums.ente.io/preview/?fileID=${id}`;
  35. };
  36. export const getUploadEndpoint = () => {
  37. const endpoint = process.env.NEXT_PUBLIC_ENTE_UPLOAD_ENDPOINT;
  38. if (isDevDeployment() && endpoint) {
  39. return endpoint;
  40. }
  41. return `https://uploader.ente.io`;
  42. };
  43. export const getPaymentsURL = () => {
  44. const paymentsURL = process.env.NEXT_PUBLIC_ENTE_PAYMENT_ENDPOINT;
  45. if (isDevDeployment() && paymentsURL) {
  46. return paymentsURL;
  47. }
  48. return `https://payments.ente.io`;
  49. };
  50. export const getAlbumsURL = () => {
  51. const albumsURL = process.env.NEXT_PUBLIC_ENTE_ALBUM_ENDPOINT;
  52. if (isDevDeployment() && albumsURL) {
  53. return albumsURL;
  54. }
  55. return `https://albums.ente.io`;
  56. };
  57. // getFamilyPortalURL returns the endpoint for the family dashboard which can be used to
  58. // create or manage family.
  59. export const getFamilyPortalURL = () => {
  60. const familyURL = process.env.NEXT_PUBLIC_ENTE_FAMILY_PORTAL_ENDPOINT;
  61. if (isDevDeployment() && familyURL) {
  62. return familyURL;
  63. }
  64. return `https://family.ente.io`;
  65. };
  66. /*
  67. It's a dev deployment (and should use the environment override for endpoints ) in three cases:
  68. 1. when the URL opened is that of the staging web app, or
  69. 2. when the URL opened is that of the staging album app, or
  70. 3. if the app is running locally (hence node_env is development)
  71. 4. if the app is running in test mode
  72. */
  73. export const isDevDeployment = () => {
  74. if (globalThis?.location) {
  75. return (
  76. process.env.NEXT_PUBLIC_ENTE_WEB_ENDPOINT ===
  77. globalThis.location.origin ||
  78. process.env.NEXT_PUBLIC_ENTE_ALBUM_ENDPOINT ===
  79. globalThis.location.origin ||
  80. process.env.NEXT_PUBLIC_IS_TEST_APP === 'true' ||
  81. process.env.NODE_ENV === 'development'
  82. );
  83. }
  84. };