api.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. * A build is considered as a development build if the NODE_ENV environment
  68. * variable is set to 'development'.
  69. *
  70. * This automatically happens when we run `yarn dev:foo`, but we can also
  71. * explictly set it to development before invoking the build. From Next.js docs:
  72. *
  73. * > If the environment variable NODE_ENV is unassigned, Next.js
  74. * automatically assigns development when running the `next dev` command,
  75. * or production for all other commands.
  76. */
  77. export const isDevDeployment = () => {
  78. return process.env.NODE_ENV === 'development';
  79. };