@@ -3,6 +3,16 @@ import fs from 'fs';
33import path from 'path' ;
44import type { ProviderPersonMapping , PlatformType } from '@fsf/shared' ;
55import { augmentationService } from '../services/augmentation.service.js' ;
6+ import { linkWikipedia , linkAncestry , linkWikiTree , linkLinkedIn } from '../services/platform-linking.service.js' ;
7+ import {
8+ getWikiPhotoPath , hasWikiPhoto ,
9+ getAncestryPhotoPath , hasAncestryPhoto ,
10+ getWikiTreePhotoPath , hasWikiTreePhoto ,
11+ getFamilySearchPhotoPath , hasFamilySearchPhoto ,
12+ getLinkedInPhotoPath , hasLinkedInPhoto ,
13+ fetchPhotoFromPlatform ,
14+ } from '../services/augmentation-photo.service.js' ;
15+ import { getProviderMappings , addProviderMapping , removeProviderMapping } from '../services/provider-mapping.service.js' ;
616import { logger } from '../lib/logger.js' ;
717import { sanitizePersonId , isValidUrl } from '../utils/validation.js' ;
818import { PHOTOS_DIR } from '../utils/paths.js' ;
@@ -102,7 +112,7 @@ router.get('/:personId', async (req: Request, res: Response) => {
102112} ) ;
103113
104114// Link a Wikipedia article to a person
105- router . post ( '/:personId/wikipedia' , linkPlatform ( 'wikipedia.org' , 'Wikipedia' , ( id , url ) => augmentationService . linkWikipedia ( id , url ) ) ) ;
115+ router . post ( '/:personId/wikipedia' , linkPlatform ( 'wikipedia.org' , 'Wikipedia' , ( id , url ) => linkWikipedia ( id , url ) ) ) ;
106116
107117// Update custom augmentation data
108118router . put ( '/:personId' , async ( req : Request , res : Response ) => {
@@ -130,43 +140,43 @@ router.put('/:personId', async (req: Request, res: Response) => {
130140} ) ;
131141
132142// Serve Wikipedia photo
133- router . get ( '/:personId/wiki-photo' , servePhoto ( id => augmentationService . getWikiPhotoPath ( id ) , 'Wiki' ) ) ;
143+ router . get ( '/:personId/wiki-photo' , servePhoto ( id => getWikiPhotoPath ( id ) , 'Wiki' ) ) ;
134144
135145// Check if wiki photo exists
136- router . get ( '/:personId/wiki-photo/exists' , checkPhotoExists ( id => augmentationService . hasWikiPhoto ( id ) ) ) ;
146+ router . get ( '/:personId/wiki-photo/exists' , checkPhotoExists ( id => hasWikiPhoto ( id ) ) ) ;
137147
138148// Link an Ancestry profile to a person
139- router . post ( '/:personId/ancestry' , linkPlatform ( 'ancestry.com' , 'Ancestry' , ( id , url ) => augmentationService . linkAncestry ( id , url ) ) ) ;
149+ router . post ( '/:personId/ancestry' , linkPlatform ( 'ancestry.com' , 'Ancestry' , ( id , url ) => linkAncestry ( id , url ) ) ) ;
140150
141151// Serve Ancestry photo
142- router . get ( '/:personId/ancestry-photo' , servePhoto ( id => augmentationService . getAncestryPhotoPath ( id ) , 'Ancestry' ) ) ;
152+ router . get ( '/:personId/ancestry-photo' , servePhoto ( id => getAncestryPhotoPath ( id ) , 'Ancestry' ) ) ;
143153
144154// Check if ancestry photo exists
145- router . get ( '/:personId/ancestry-photo/exists' , checkPhotoExists ( id => augmentationService . hasAncestryPhoto ( id ) ) ) ;
155+ router . get ( '/:personId/ancestry-photo/exists' , checkPhotoExists ( id => hasAncestryPhoto ( id ) ) ) ;
146156
147157// Link a WikiTree profile to a person
148- router . post ( '/:personId/wikitree' , linkPlatform ( 'wikitree.com' , 'WikiTree' , ( id , url ) => augmentationService . linkWikiTree ( id , url ) ) ) ;
158+ router . post ( '/:personId/wikitree' , linkPlatform ( 'wikitree.com' , 'WikiTree' , ( id , url ) => linkWikiTree ( id , url ) ) ) ;
149159
150160// Serve WikiTree photo
151- router . get ( '/:personId/wikitree-photo' , servePhoto ( id => augmentationService . getWikiTreePhotoPath ( id ) , 'WikiTree' ) ) ;
161+ router . get ( '/:personId/wikitree-photo' , servePhoto ( id => getWikiTreePhotoPath ( id ) , 'WikiTree' ) ) ;
152162
153163// Check if wikitree photo exists
154- router . get ( '/:personId/wikitree-photo/exists' , checkPhotoExists ( id => augmentationService . hasWikiTreePhoto ( id ) ) ) ;
164+ router . get ( '/:personId/wikitree-photo/exists' , checkPhotoExists ( id => hasWikiTreePhoto ( id ) ) ) ;
155165
156166// Serve FamilySearch photo
157- router . get ( '/:personId/familysearch-photo' , servePhoto ( id => augmentationService . getFamilySearchPhotoPath ( id ) , 'FamilySearch' ) ) ;
167+ router . get ( '/:personId/familysearch-photo' , servePhoto ( id => getFamilySearchPhotoPath ( id ) , 'FamilySearch' ) ) ;
158168
159169// Check if FamilySearch photo exists
160- router . get ( '/:personId/familysearch-photo/exists' , checkPhotoExists ( id => augmentationService . hasFamilySearchPhoto ( id ) ) ) ;
170+ router . get ( '/:personId/familysearch-photo/exists' , checkPhotoExists ( id => hasFamilySearchPhoto ( id ) ) ) ;
161171
162172// Link a LinkedIn profile to a person
163- router . post ( '/:personId/linkedin' , linkPlatform ( 'linkedin.com' , 'LinkedIn' , ( id , url ) => augmentationService . linkLinkedIn ( id , url ) ) ) ;
173+ router . post ( '/:personId/linkedin' , linkPlatform ( 'linkedin.com' , 'LinkedIn' , ( id , url ) => linkLinkedIn ( id , url ) ) ) ;
164174
165175// Serve LinkedIn photo
166- router . get ( '/:personId/linkedin-photo' , servePhoto ( id => augmentationService . getLinkedInPhotoPath ( id ) , 'LinkedIn' ) ) ;
176+ router . get ( '/:personId/linkedin-photo' , servePhoto ( id => getLinkedInPhotoPath ( id ) , 'LinkedIn' ) ) ;
167177
168178// Check if LinkedIn photo exists
169- router . get ( '/:personId/linkedin-photo/exists' , checkPhotoExists ( id => augmentationService . hasLinkedInPhoto ( id ) ) ) ;
179+ router . get ( '/:personId/linkedin-photo/exists' , checkPhotoExists ( id => hasLinkedInPhoto ( id ) ) ) ;
170180
171181// Fetch and download photo from a linked platform
172182router . post ( '/:personId/fetch-photo/:platform' , async ( req : Request , res : Response ) => {
@@ -179,7 +189,7 @@ router.post('/:personId/fetch-photo/:platform', async (req: Request, res: Respon
179189 return ;
180190 }
181191
182- const data = await augmentationService . fetchPhotoFromPlatform ( personId , platform as any ) . catch ( err => {
192+ const data = await fetchPhotoFromPlatform ( personId , platform as any ) . catch ( err => {
183193 logger . error ( 'augment' , `Error fetching photo from ${ platform } : ${ err . message } ` ) ;
184194 res . status ( 500 ) . json ( { success : false , error : err . message } ) ;
185195 return null ;
@@ -193,7 +203,7 @@ router.post('/:personId/fetch-photo/:platform', async (req: Request, res: Respon
193203// Get all provider mappings for a person
194204router . get ( '/:personId/provider-links' , ( req : Request , res : Response ) => {
195205 const personId = sanitizePersonId ( req . params . personId ) ;
196- const mappings = augmentationService . getProviderMappings ( personId ) ;
206+ const mappings = getProviderMappings ( personId ) ;
197207 res . json ( { success : true , data : mappings } ) ;
198208} ) ;
199209
@@ -226,7 +236,7 @@ router.post('/:personId/provider-link', (req: Request, res: Response) => {
226236 matchedBy : matchedBy || 'manual' ,
227237 } ;
228238
229- const data = augmentationService . addProviderMapping ( personId , mapping ) ;
239+ const data = addProviderMapping ( personId , mapping ) ;
230240 res . json ( { success : true , data } ) ;
231241} ) ;
232242
@@ -235,7 +245,7 @@ router.delete('/:personId/provider-link/:providerId', (req: Request, res: Respon
235245 const personId = sanitizePersonId ( req . params . personId ) ;
236246 const { providerId } = req . params ;
237247
238- const data = augmentationService . removeProviderMapping ( personId , providerId ) ;
248+ const data = removeProviderMapping ( personId , providerId ) ;
239249
240250 if ( ! data ) {
241251 res . status ( 404 ) . json ( { success : false , error : 'No augmentation data found' } ) ;
0 commit comments