Skip to content

Commit

Permalink
docs: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
meenahoda committed Jan 4, 2019
1 parent b5f4bf4 commit ed226c0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ const sp = new Sharepoint('URL HERE')
sp.authenticate()
sp.getWebEndpoint()
sp.getContents(dirPath)
sp.createFolder(options) // options = { dirPath, folderName }
sp.deleteFolder(options) // options = { dirPath, folderName }
sp.createFile(options) // options = { dirPath, fileName, data }
sp.deleteFile(options) // options = { dirPath, fileName }
sp.createFileChunked(options) // options = { dirPath, fileName, stream, fileSize, chunkSize }
sp.getContents(patb)
sp.createFolder(path)
sp.deleteFolder(path)
sp.createFile(options) // options = { path, fileName, data }
sp.deleteFile(options) // options = { path, fileName }
sp.createFileChunked(options) // options = { path, fileName, stream, fileSize, chunkSize }
```

## <a name="test"></a>Test
Expand Down
26 changes: 13 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ class Sharepoint {
return data.d.GetContextWebInformation.FormDigestValue
}

async getContents (dirPath) {
async getContents (path) {
this.checkHeaders()

const { url, headers, site } = this

const get = type => {
return axios.get(
`${url}/_api/web/GetFolderByServerRelativeUrl('${site.serverRelativeUrl}${dirPath}')/${type}`,
`${url}/_api/web/GetFolderByServerRelativeUrl('${site.serverRelativeUrl}${path}')/${type}`,
{ headers, responseType: 'json' }
)
}
Expand Down Expand Up @@ -142,7 +142,7 @@ class Sharepoint {
this.checkHeaders()
const formDigestValue = await this.getFormDigestValue()

const { dirPath, fileName, data } = options
const { path, fileName, data } = options

if (!fileName) {
throw new Error('You must provide a file name.')
Expand All @@ -154,7 +154,7 @@ class Sharepoint {

await axios({
method: 'post',
url: `${this.url}/_api/web/GetFolderByServerRelativeUrl('${this.site.serverRelativeUrl}${dirPath}')/Files/add(url='${fileName}', overwrite=true)`,
url: `${this.url}/_api/web/GetFolderByServerRelativeUrl('${this.site.serverRelativeUrl}${path}')/Files/add(url='${fileName}', overwrite=true)`,
data,
headers: {
...this.headers,
Expand All @@ -165,15 +165,15 @@ class Sharepoint {

async createFileChunked (options) {
const {
dirPath, fileName, stream, fileSize
path, fileName, stream, fileSize
} = options

const chunkSize = options.chunkSize || 65536
this.checkHeaders()
const formDigestValue = await this.getFormDigestValue()

await this.createFile({
dirPath,
path,
fileName,
data: ' '
})
Expand All @@ -192,7 +192,7 @@ class Sharepoint {
firstChunk = false
const response = await axios({
method: 'post',
url: `${self.url}/_api/web/getfilebyserverrelativeurl('${self.site.serverRelativeUrl}${dirPath}/${fileName}')/startupload(uploadId=guid'${uploadId}')`,
url: `${self.url}/_api/web/getfilebyserverrelativeurl('${self.site.serverRelativeUrl}${path}/${fileName}')/startupload(uploadId=guid'${uploadId}')`,
data,
headers: {
...self.headers,
Expand All @@ -203,7 +203,7 @@ class Sharepoint {
} else if (sent + chunkSize >= fileSize) {
await axios({
method: 'post',
url: `${self.url}/_api/web/getfilebyserverrelativeurl('${self.site.serverRelativeUrl}${dirPath}/${fileName}')/finishupload(uploadId=guid'${uploadId}',fileoffset=${sent})`,
url: `${self.url}/_api/web/getfilebyserverrelativeurl('${self.site.serverRelativeUrl}${path}/${fileName}')/finishupload(uploadId=guid'${uploadId}',fileoffset=${sent})`,
data,
headers: {
...self.headers,
Expand All @@ -214,7 +214,7 @@ class Sharepoint {
} else {
const response = await axios({
method: 'post',
url: `${self.url}/_api/web/getfilebyserverrelativeurl('${self.site.serverRelativeUrl}${dirPath}/${fileName}')/continueupload(uploadId=guid'${uploadId}',fileoffset=${sent})`,
url: `${self.url}/_api/web/getfilebyserverrelativeurl('${self.site.serverRelativeUrl}${path}/${fileName}')/continueupload(uploadId=guid'${uploadId}',fileoffset=${sent})`,
data,
headers: {
...self.headers,
Expand All @@ -228,7 +228,7 @@ class Sharepoint {
stream.destroy()
await axios({
method: 'post',
url: `${self.url}/_api/web/getfilebyserverrelativeurl('${self.site.serverRelativeUrl}${dirPath}/${fileName}')/cancelupload(uploadId=guid'${uploadId}')`,
url: `${self.url}/_api/web/getfilebyserverrelativeurl('${self.site.serverRelativeUrl}${path}/${fileName}')/cancelupload(uploadId=guid'${uploadId}')`,
headers: {
...self.headers,
'X-RequestDigest': formDigestValue
Expand All @@ -241,7 +241,7 @@ class Sharepoint {
stream.on('error', async err => {
await axios({
method: 'post',
url: `${self.url}/_api/web/getfilebyserverrelativeurl('${self.site.serverRelativeUrl}${dirPath}/${fileName}')/cancelupload(uploadId=guid'${uploadId}')`,
url: `${self.url}/_api/web/getfilebyserverrelativeurl('${self.site.serverRelativeUrl}${path}/${fileName}')/cancelupload(uploadId=guid'${uploadId}')`,
headers: {
...self.headers,
'X-RequestDigest': formDigestValue
Expand All @@ -258,15 +258,15 @@ class Sharepoint {
this.checkHeaders()
const formDigestValue = await this.getFormDigestValue()

const { dirPath, fileName } = options
const { path, fileName } = options

if (!fileName) {
throw new Error('You must provide a file name.')
}

await axios({
method: 'post',
url: `${this.url}/_api/web/GetFileByServerRelativeUrl('${this.site.serverRelativeUrl}${dirPath}/${fileName}')`,
url: `${this.url}/_api/web/GetFileByServerRelativeUrl('${this.site.serverRelativeUrl}${path}/${fileName}')`,
headers: {
...this.headers,
'X-RequestDigest': formDigestValue,
Expand Down
16 changes: 8 additions & 8 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('Tests', function () {

try {
await sharepoint.createFile({
dirPath: process.env.SHAREPOINT_DIR_PATH,
path: process.env.SHAREPOINT_DIR_PATH,
data: '...'
})
} catch (e) {
Expand All @@ -136,7 +136,7 @@ describe('Tests', function () {

try {
await sharepoint.createFile({
dirPath: process.env.SHAREPOINT_DIR_PATH,
path: process.env.SHAREPOINT_DIR_PATH,
fileName: 'new file'
})
} catch (e) {
Expand All @@ -151,7 +151,7 @@ describe('Tests', function () {

try {
await sharepoint.deleteFile({
dirPath: process.env.SHAREPOINT_DIR_PATH
path: process.env.SHAREPOINT_DIR_PATH
})
} catch (e) {
error = e.message
Expand All @@ -177,7 +177,7 @@ describe('Tests', function () {

it('create file in new folder', async () => {
await sharepoint.createFile({
dirPath: `${process.env.SHAREPOINT_DIR_PATH}/${FOLDER_NAME}`,
path: `${process.env.SHAREPOINT_DIR_PATH}/${FOLDER_NAME}`,
fileName: FILE_NAME,
data: 'Testing 1 2 3...'
})
Expand All @@ -191,7 +191,7 @@ describe('Tests', function () {

it('delete the new file', async () => {
await sharepoint.deleteFile({
dirPath: `${process.env.SHAREPOINT_DIR_PATH}/${FOLDER_NAME}`,
path: `${process.env.SHAREPOINT_DIR_PATH}/${FOLDER_NAME}`,
fileName: FILE_NAME
})
})
Expand All @@ -205,7 +205,7 @@ describe('Tests', function () {
const data = getBinaryData(path.resolve(__dirname, 'fixtures', FILE_NAME))

await sharepoint.createFile({
dirPath: `${process.env.SHAREPOINT_DIR_PATH}/${FOLDER_NAME}`,
path: `${process.env.SHAREPOINT_DIR_PATH}/${FOLDER_NAME}`,
fileName: FILE_NAME,
data
})
Expand All @@ -221,7 +221,7 @@ describe('Tests', function () {
const data = getBinaryData(path.resolve(__dirname, 'fixtures', FILE_NAME_1))

await sharepoint.createFile({
dirPath: `${process.env.SHAREPOINT_DIR_PATH}/${FOLDER_NAME}`,
path: `${process.env.SHAREPOINT_DIR_PATH}/${FOLDER_NAME}`,
fileName: FILE_NAME_1,
data
})
Expand All @@ -238,7 +238,7 @@ describe('Tests', function () {
const { size } = fs.statSync(filePath)
const stream = fs.createReadStream(filePath, { highWaterMark: 1024 * 2 })
await sharepoint.createFileChunked({
dirPath: `${process.env.SHAREPOINT_DIR_PATH}/${FOLDER_NAME}`,
path: `${process.env.SHAREPOINT_DIR_PATH}/${FOLDER_NAME}`,
fileName: FILE_NAME_1,
stream,
fileSize: size,
Expand Down

0 comments on commit ed226c0

Please sign in to comment.