mirror of
				https://github.com/immich-app/immich.git
				synced 2025-11-04 03:27:09 -05:00 
			
		
		
		
	fix: custom-url ssr (#20704)
This commit is contained in:
		
							parent
							
								
									d430b869ac
								
							
						
					
					
						commit
						a5760129f0
					
				@ -9,7 +9,7 @@ import {
 | 
				
			|||||||
} from '@immich/sdk';
 | 
					} from '@immich/sdk';
 | 
				
			||||||
import { createUserDto, uuidDto } from 'src/fixtures';
 | 
					import { createUserDto, uuidDto } from 'src/fixtures';
 | 
				
			||||||
import { errorDto } from 'src/responses';
 | 
					import { errorDto } from 'src/responses';
 | 
				
			||||||
import { app, asBearerAuth, shareUrl, utils } from 'src/utils';
 | 
					import { app, asBearerAuth, baseUrl, shareUrl, utils } from 'src/utils';
 | 
				
			||||||
import request from 'supertest';
 | 
					import request from 'supertest';
 | 
				
			||||||
import { beforeAll, describe, expect, it } from 'vitest';
 | 
					import { beforeAll, describe, expect, it } from 'vitest';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -78,6 +78,7 @@ describe('/shared-links', () => {
 | 
				
			|||||||
          type: SharedLinkType.Album,
 | 
					          type: SharedLinkType.Album,
 | 
				
			||||||
          albumId: metadataAlbum.id,
 | 
					          albumId: metadataAlbum.id,
 | 
				
			||||||
          showMetadata: true,
 | 
					          showMetadata: true,
 | 
				
			||||||
 | 
					          slug: 'metadata-album',
 | 
				
			||||||
        }),
 | 
					        }),
 | 
				
			||||||
        utils.createSharedLink(user1.accessToken, {
 | 
					        utils.createSharedLink(user1.accessToken, {
 | 
				
			||||||
          type: SharedLinkType.Album,
 | 
					          type: SharedLinkType.Album,
 | 
				
			||||||
@ -138,6 +139,17 @@ describe('/shared-links', () => {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  describe('GET /s/:slug', () => {
 | 
				
			||||||
 | 
					    it('should work for slug auth', async () => {
 | 
				
			||||||
 | 
					      const resp = await request(baseUrl).get(`/s/${linkWithMetadata.slug}`);
 | 
				
			||||||
 | 
					      expect(resp.status).toBe(200);
 | 
				
			||||||
 | 
					      expect(resp.header['content-type']).toContain('text/html');
 | 
				
			||||||
 | 
					      expect(resp.text).toContain(
 | 
				
			||||||
 | 
					        `<meta name="description" content="${metadataAlbum.assets.length} shared photos & videos" />`,
 | 
				
			||||||
 | 
					      );
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  describe('GET /shared-links', () => {
 | 
					  describe('GET /shared-links', () => {
 | 
				
			||||||
    it('should require authentication', async () => {
 | 
					    it('should require authentication', async () => {
 | 
				
			||||||
      const { status, body } = await request(app).get('/shared-links');
 | 
					      const { status, body } = await request(app).get('/shared-links');
 | 
				
			||||||
 | 
				
			|||||||
@ -76,23 +76,36 @@ export class ApiService {
 | 
				
			|||||||
      let status = 200;
 | 
					      let status = 200;
 | 
				
			||||||
      let html = index;
 | 
					      let html = index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      const shareMatches = request.url.match(/^\/share\/(.+)$/);
 | 
					      const defaultDomain = request.host ? `${request.protocol}://${request.host}` : undefined;
 | 
				
			||||||
      if (shareMatches) {
 | 
					
 | 
				
			||||||
 | 
					      let meta: OpenGraphTags | null = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      const shareKey = request.url.match(/^\/share\/(.+)$/);
 | 
				
			||||||
 | 
					      if (shareKey) {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
          const key = shareMatches[1];
 | 
					          const key = shareKey[1];
 | 
				
			||||||
          const auth = await this.authService.validateSharedLinkKey(key);
 | 
					          const auth = await this.authService.validateSharedLinkKey(key);
 | 
				
			||||||
          const meta = await this.sharedLinkService.getMetadataTags(
 | 
					          meta = await this.sharedLinkService.getMetadataTags(auth, defaultDomain);
 | 
				
			||||||
            auth,
 | 
					 | 
				
			||||||
            request.host ? `${request.protocol}://${request.host}` : undefined,
 | 
					 | 
				
			||||||
          );
 | 
					 | 
				
			||||||
          if (meta) {
 | 
					 | 
				
			||||||
            html = render(index, meta);
 | 
					 | 
				
			||||||
          }
 | 
					 | 
				
			||||||
        } catch {
 | 
					        } catch {
 | 
				
			||||||
          status = 404;
 | 
					          status = 404;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      const shareSlug = request.url.match(/^\/s\/(.+)$/);
 | 
				
			||||||
 | 
					      if (shareSlug) {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					          const slug = shareSlug[1];
 | 
				
			||||||
 | 
					          const auth = await this.authService.validateSharedLinkSlug(slug);
 | 
				
			||||||
 | 
					          meta = await this.sharedLinkService.getMetadataTags(auth, defaultDomain);
 | 
				
			||||||
 | 
					        } catch {
 | 
				
			||||||
 | 
					          status = 404;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (meta) {
 | 
				
			||||||
 | 
					        html = render(index, meta);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      res.status(status).type('text/html').header('Cache-Control', 'no-store').send(html);
 | 
					      res.status(status).type('text/html').header('Cache-Control', 'no-store').send(html);
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user