Skip to content

Commit 20c5e61

Browse files
committed
Added apis
1 parent ed32e88 commit 20c5e61

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

src/trpc/routers/microsoft.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,86 @@ export const microsoftRouter = createTRPCRouter({
129129
tenantName: connection.tenantName,
130130
};
131131
}),
132+
133+
/**
134+
* Get drives (document libraries) for a site
135+
*/
136+
drives: protectedProcedure
137+
.input(z.object({ siteId: z.string() }))
138+
.query(async ({ ctx, input }) => {
139+
if (!ctx.user) {
140+
throw new TRPCError({ code: 'UNAUTHORIZED', message: 'User not found' });
141+
}
142+
143+
try {
144+
const permissionsClient = new PermissionsClient(ctx.user.id);
145+
const drives = await permissionsClient.getSiteDrives(input.siteId);
146+
147+
return drives.map(drive => ({
148+
id: drive.id,
149+
name: drive.name,
150+
webUrl: drive.webUrl,
151+
driveType: drive.driveType,
152+
}));
153+
} catch (error) {
154+
console.error('Error fetching drives:', error);
155+
return [];
156+
}
157+
}),
158+
159+
/**
160+
* Get folder contents (children)
161+
*/
162+
folderContents: protectedProcedure
163+
.input(z.object({
164+
driveId: z.string(),
165+
folderId: z.string().default('root'),
166+
}))
167+
.query(async ({ ctx, input }) => {
168+
if (!ctx.user) {
169+
throw new TRPCError({ code: 'UNAUTHORIZED', message: 'User not found' });
170+
}
171+
172+
try {
173+
const permissionsClient = new PermissionsClient(ctx.user.id);
174+
const items = await permissionsClient.listDriveItemChildren(input.driveId, input.folderId);
175+
176+
return items.map(item => ({
177+
id: item.id,
178+
name: item.name,
179+
webUrl: item.webUrl,
180+
isFolder: !!item.folder,
181+
childCount: item.folder?.childCount || 0,
182+
mimeType: item.file?.mimeType || null,
183+
}));
184+
} catch (error) {
185+
console.error('Error fetching folder contents:', error);
186+
return [];
187+
}
188+
}),
189+
190+
/**
191+
* Get site details by ID
192+
*/
193+
site: protectedProcedure
194+
.input(z.object({ siteId: z.string() }))
195+
.query(async ({ ctx, input }) => {
196+
if (!ctx.user) {
197+
throw new TRPCError({ code: 'UNAUTHORIZED', message: 'User not found' });
198+
}
199+
200+
try {
201+
const permissionsClient = new PermissionsClient(ctx.user.id);
202+
const site = await permissionsClient.getSiteById(input.siteId);
203+
204+
return {
205+
id: site.id,
206+
displayName: site.displayName,
207+
webUrl: site.webUrl,
208+
};
209+
} catch (error) {
210+
console.error('Error fetching site:', error);
211+
return null;
212+
}
213+
}),
132214
});

0 commit comments

Comments
 (0)