Skip to content

Commit

Permalink
fix: haven't admin permission
Browse files Browse the repository at this point in the history
ask for tenant name
  • Loading branch information
bsorrentino committed Jan 17, 2024
1 parent 4bd0384 commit d0dba94
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bin/osts-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ${chalk.blue("osts-cli version: ")}${chalk.bgBlue(version)}
Usage:
========
osts list[--path] // list OSTS packages in SPO path.
osts list [--path] // list OSTS packages in SPO path.
osts unpack [--path, -p <dest dir> [--dts] ] // download OSTS package and extract body (.ts) to dest dir (default '${DEFAULT_PATH}').
// If --dts is specified an Office Script Simplified TS Declaration file will be copied in dest dir
Expand Down
20 changes: 14 additions & 6 deletions bin/osts-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export async function copyOfficeScriptSimplifiedDeclaration(bodyDirPath) {
export async function listOfficeScript(prefs) {
const list_parameters = [
'--webUrl', prefs.weburl,
'--folder', prefs.folder,
'--folderUrl', prefs.folder,
'--query', "[?ends_with(Name, '.osts')]",
'--recursive'
];
Expand All @@ -119,10 +119,18 @@ export const getWebUrl = async () => {
const args = [
'--query', `[?Owner=='${status.connectedAs}'].Url | [0]`
];
const cmd_list = await $ `m365 onedrive list ${args}`.quiet();
const url = JSON.parse(cmd_list.stdout);
if (url === null) {
throw `Owner '${status.connectedAs}' not found!`;
try {
const cmd_list = await $ `m365 onedrive list ${args}`.quiet();
const url = JSON.parse(cmd_list.stdout);
if (url === null) {
throw `Owner '${status.connectedAs}' not found!`;
}
return url;
}
catch (e) {
const tenant = await question(`give me tenant name: `);
const url = `https://${tenant}-my.sharepoint.com/personal/${status.connectedAs.replace(/[.@]/g, '_')}`;
// console.debug( 'url', url)
return url;
}
return url;
};
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/osts-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ${chalk.blue("osts-cli version: ")}${chalk.bgBlue(version)}
Usage:
========
osts list[--path] // list OSTS packages in SPO path.
osts list [--path] // list OSTS packages in SPO path.
osts unpack [--path, -p <dest dir> [--dts] ] // download OSTS package and extract body (.ts) to dest dir (default '${DEFAULT_PATH}').
// If --dts is specified an Office Script Simplified TS Declaration file will be copied in dest dir
Expand Down
27 changes: 20 additions & 7 deletions src/osts-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,11 @@ export async function copyOfficeScriptSimplifiedDeclaration( bodyDirPath:string

const list_parameters = [
'--webUrl', prefs.weburl,
'--folder', prefs.folder,
'--folderUrl', prefs.folder,
'--query', "[?ends_with(Name, '.osts')]",
'--recursive'
]

const result = await $`m365 spo file list ${list_parameters}`.quiet()

const spoFileListResult = JSON.parse( result.stdout ) as Array<SPOFile>
Expand Down Expand Up @@ -211,13 +212,25 @@ export const getWebUrl = async () => {
'--query', `[?Owner=='${status.connectedAs}'].Url | [0]`
]

const cmd_list = await $`m365 onedrive list ${args}`.quiet()

const url = JSON.parse(cmd_list.stdout)
try {
const cmd_list = await $`m365 onedrive list ${args}`.quiet()

if( url === null ) {
throw `Owner '${status.connectedAs}' not found!`
const url = JSON.parse(cmd_list.stdout)

if( url === null ) {
throw `Owner '${status.connectedAs}' not found!`
}

return url

}
catch( e ) {

const tenant = await question( `give me tenant name: `)

return url
const url = `https://${tenant}-my.sharepoint.com/personal/${status.connectedAs.replace(/[.@]/g, '_')}`

// console.debug( 'url', url)
return url
}
}

0 comments on commit d0dba94

Please sign in to comment.