Skip to content

Commit 57e8324

Browse files
committed
legacy document links
Add support for legacy links to documents closes #1508
1 parent 13ab709 commit 57e8324

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

server/src/document/document.controller.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ export class DocumentController {
9393
}
9494
}
9595

96+
@Get("/package/sites/*")
97+
async streamPackageDocByUrl(@Param() sharepointRelativePath, @Res() res) {
98+
const id = await this.documentService.getPackageDocumentId(
99+
sharepointRelativePath[0]
100+
);
101+
102+
const stream = await this.documentService.getPackageDocument(id);
103+
stream.pipe(res);
104+
}
105+
96106
@Get("/package/*")
97107
async streamPackageDoc(@Param() sharepointRelativePath, @Res() res) {
98108
const stream = await this.documentService.getPackageDocument(
@@ -102,6 +112,16 @@ export class DocumentController {
102112
stream.pipe(res);
103113
}
104114

115+
@Get("/artifact/sites/*")
116+
async streamArtifactDocByUrl(@Param() sharepointRelativePath, @Res() res) {
117+
const id = await this.documentService.getArtifactDocumentId(
118+
sharepointRelativePath[0]
119+
);
120+
121+
const stream = await this.documentService.getArtifactDocument(id);
122+
stream.pipe(res);
123+
}
124+
105125
@Get("/artifact/*")
106126
async streamArtifactDoc(@Param() sharepointRelativePath, @Res() res) {
107127
const stream = await this.documentService.getArtifactDocument(
@@ -111,6 +131,19 @@ export class DocumentController {
111131
stream.pipe(res);
112132
}
113133

134+
@Get("/projectaction/sites/*")
135+
async streamProjectactionDocByUrl(
136+
@Param() sharepointRelativePath,
137+
@Res() res
138+
) {
139+
const id = await this.documentService.getProjectactionDocumentId(
140+
sharepointRelativePath[0]
141+
);
142+
143+
const stream = await this.documentService.getProjectactionDocument(id);
144+
stream.pipe(res);
145+
}
146+
114147
@Get("/projectaction/*")
115148
async streamProjectactionDoc(@Param() sharepointRelativePath, @Res() res) {
116149
const stream = await this.documentService.getProjectactionDocument(
@@ -120,6 +153,16 @@ export class DocumentController {
120153
stream.pipe(res);
121154
}
122155

156+
@Get("/disposition/sites/*")
157+
async streamDispositionDocByUrl(@Param() sharepointRelativePath, @Res() res) {
158+
const id = await this.documentService.getDispositionDocumentId(
159+
sharepointRelativePath[0]
160+
);
161+
162+
const stream = await this.documentService.getDispositionDocument(id);
163+
stream.pipe(res);
164+
}
165+
123166
@Get("/disposition/*")
124167
async streamDispositionDoc(@Param() sharepointRelativePath, @Res() res) {
125168
const stream = await this.documentService.getDispositionDocument(

server/src/document/document.service.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ export class DocumentService {
8585
private readonly crmService: CrmService,
8686
private readonly sharepointService: SharepointService
8787
) {}
88+
public async getPackageDocumentId(relativeUrl: string) {
89+
const driveId = this.sharepointService.driveIdMap.dcp_package;
90+
return await this.sharepointService.getSharepointFileId(
91+
driveId,
92+
relativeUrl
93+
);
94+
}
8895
// For info on the path param,
8996
// see above documentation for the getRecordIdFromDocumentPath function
9097
public async getPackageDocument(fileId) {
@@ -135,6 +142,14 @@ export class DocumentService {
135142
}
136143
}
137144

145+
public async getArtifactDocumentId(relativeUrl: string) {
146+
const driveId = this.sharepointService.driveIdMap.dcp_artifact;
147+
return await this.sharepointService.getSharepointFileId(
148+
driveId,
149+
relativeUrl
150+
);
151+
}
152+
138153
public async getArtifactDocument(fileId) {
139154
const driveId = this.sharepointService.driveIdMap.dcp_artifact;
140155
const {
@@ -172,6 +187,14 @@ export class DocumentService {
172187
}
173188
}
174189

190+
public async getProjectactionDocumentId(relativeUrl: string) {
191+
const driveId = this.sharepointService.driveIdMap.dcp_projectaction;
192+
return await this.sharepointService.getSharepointFileId(
193+
driveId,
194+
relativeUrl
195+
);
196+
}
197+
175198
public async getProjectactionDocument(fileId: string) {
176199
const driveId = this.sharepointService.driveIdMap.dcp_projectaction;
177200
const {
@@ -209,6 +232,15 @@ export class DocumentService {
209232
}
210233
}
211234

235+
public async getDispositionDocumentId(relativeUrl: string) {
236+
const driveId = this.sharepointService.driveIdMap
237+
.dcp_communityboarddisposition;
238+
return await this.sharepointService.getSharepointFileId(
239+
driveId,
240+
relativeUrl
241+
);
242+
}
243+
212244
public async getDispositionDocument(fileId) {
213245
const driveId = this.sharepointService.driveIdMap
214246
.dcp_communityboarddisposition;

server/src/sharepoint/sharepoint.service.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,46 @@ export class SharepointService {
225225
const response = await fetch(url, options);
226226
return await response.json();
227227
}
228+
229+
async getSharepointFileId(driveId: string, relativeUrl: string) {
230+
const filePath = relativeUrl.split("/");
231+
if (filePath.length < 2)
232+
throw new HttpException(
233+
{
234+
code: "DISPOSITION_ID_PATH",
235+
title: "Disposition ID Path Error"
236+
},
237+
HttpStatus.BAD_REQUEST
238+
);
239+
const folderName = filePath[filePath.length - 2];
240+
const fileName = filePath[filePath.length - 1];
241+
242+
const { accessToken } = await this.msalProvider.getGraphClientToken();
243+
const url = `${
244+
this.msalProvider.sharePointSiteUrl
245+
}/drives/${driveId}/root:/${folderName}:/children?$filter=(name eq '${fileName}')&$select=id`;
246+
const options = {
247+
headers: {
248+
method: "GET",
249+
Authorization: `Bearer ${accessToken}`,
250+
Accept: "application/json"
251+
}
252+
};
253+
254+
const response = await fetch(url, options);
255+
const data = (await response.json()) as
256+
| { value: Array<{ id: string }> }
257+
| { message: string };
258+
if ("value" in data && data.value.length > 0) {
259+
return data.value[0].id;
260+
} else {
261+
throw new HttpException(
262+
{
263+
code: "DISPOSITION_ID_RESULT",
264+
title: "Disposition ID Result Error"
265+
},
266+
HttpStatus.NOT_FOUND
267+
);
268+
}
269+
}
228270
}

0 commit comments

Comments
 (0)