Skip to content

Instantly share code, notes, and snippets.

@sebastian-meier
Created April 11, 2022 19:00
Show Gist options
  • Save sebastian-meier/2c8235032832d32a58fbe95ce36b31cf to your computer and use it in GitHub Desktop.
Save sebastian-meier/2c8235032832d32a58fbe95ce36b31cf to your computer and use it in GitHub Desktop.
NextCloud batch share link create and collect script

I use our university's NextCloud instance to host my remote teaching videos. But manually generating all those share links that I need is no fun.

Open the folder with all the videos you want to generate share links for. And execute the script. The script will go through the list and click the share button, then click the generate share link button, the resulting share link is than stored in an array and returned in the end.

The script has a filter to check for specifc extensions only.

NextCloud can be a bit slow at times (at least out instance, so you might need to modify the timeout variable.

You need to scroll once to the end of the page, to load all the data.

This is not a scraper or api script, this interacts with the actual website. It is probably not the best of doing it. But it gets the job done.

(async () => {
const acceptedExt = ['mp4'];
const timeOut = 3000;
const results = [];
const files = document.querySelectorAll('#fileList tr');
for (let f = 0; f < files.length; f += 1) {
const ext = files[f].querySelector('.filename .extension').innerHTML.toLowerCase().split('.')[1];
const name = files[f].querySelector('.filename .innernametext').innerHTML;
if (acceptedExt.includes(ext)) {
files[f].querySelector('.action-share').click();
await new Promise((resolve, reject) => {
setTimeout(() => {
const copyLink = document.querySelector('.sharing-entry__copy');
if (copyLink) {
copyLink.click();
} else {
document.querySelector('.new-share-link').click();
}
setTimeout(async () => {
const url = await window.navigator.clipboard.readText();
results.push({
name,
ext,
url
});
document.querySelector('.app-sidebar__close').click();
setTimeout(() => {
resolve();
}, timeOut);
}, timeOut);
}, timeOut);
});
}
}
console.log(results);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment