1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-07 20:40:05 +00:00

feat: create file resource while deploying service pack for viya

This commit is contained in:
Saad Jutt
2021-05-30 05:58:17 +05:00
parent fe907e1c43
commit 56a1960fff
4 changed files with 104 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ import {
Context,
ContextAllAttributes,
Folder,
File,
EditContextInput,
JobDefinition,
PollOptions
@@ -532,6 +533,55 @@ export class SASViyaApiClient {
.then((res) => res.result)
}
/**
* Creates a file. Path to or URI of the parent folder is required.
* @param fileName - the name of the new file.
* @param content - the content of the new file.
* @param parentFolderPath - the full path to the parent folder. If not
* provided, the parentFolderUri must be provided.
* @param parentFolderUri - the URI (eg /folders/folders/UUID) of the parent
* folder. If not provided, the parentFolderPath must be provided.
* @param accessToken - an access token for authorizing the request.
*/
public async createFile(
fileName: string,
content: string = '',
parentFolderPath?: string,
parentFolderUri?: string,
accessToken?: string
): Promise<File> {
if (!parentFolderPath && !parentFolderUri) {
throw new Error('Path or URI of the parent folder is required.')
}
if (!parentFolderUri && parentFolderPath) {
parentFolderUri = await this.getFolderUri(parentFolderPath, accessToken)
}
const headers = {
Accept: 'application/vnd.sas.file+json',
'Content-Disposition': `filename="${fileName}";`
}
const mimeType = /.html$/.test(fileName)
? 'text/html'
: /.css$/.test(fileName)
? 'text/css'
: /.js/.test(fileName)
? 'text/javascript'
: 'text/plain'
return (
await this.requestClient.post<File>(
`/files/files?parentFolderUri=${parentFolderUri}&typeDefName=file#rawUpload`,
content,
accessToken,
mimeType,
headers
)
).result
}
/**
* Creates a folder. Path to or URI of the parent folder is required.
* @param folderName - the name of the new folder.