const {google} = require('googleapis');
const file = google.file('v1');
// Before running the sample:
// - Enable the API at:
// https://console.developers.google.com/apis/api/file.googleapis.com
// - Login into gcloud by running:
// `$ gcloud auth application-default login`
// - Install the npm module by running:
// `$ npm install googleapis`
const {google} = require('googleapis');
const file = google.file('v1beta1');
async function main() {
const auth = new google.auth.GoogleAuth({
// Scopes can be specified either as an array or as a single, space-delimited string.
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});
// Acquire an auth client, and bind it to all future calls
const authClient = await auth.getClient();
google.options({auth: authClient});
// Do the magic
const res = await file.projects.locations.operations.delete({
// The name of the operation resource to be deleted.
name: 'projects/my-project/locations/my-location/operations/my-operation',
});
console.log(res.data);
// Example response
// {}
}
main().catch(e => {
console.error(e);
throw e;
});
import * as MediaLibrary from 'expo-media-library';
import * as FileSystem from 'expo-file-system';
const { StorageAccessFramework } = FileSystem;
async function migrateAlbum(albumName: string) {
// Gets SAF URI to the album
const albumUri = StorageAccessFramework.getUriForDirectoryInRoot(albumName);
// Requests permissions
const permissions = await StorageAccessFramework.requestDirectoryPermissionsAsync(albumUri);
if (!permissions.granted) {
return;
}
const permittedUri = permissions.directoryUri;
// Checks if users selected the correct folder
if (!permittedUri.includes(albumName)) {
return;
}
const mediaLibraryPermissions = await MediaLibrary.requestPermissionsAsync();
if (!mediaLibraryPermissions.granted) {
return;
}
// Moves files from external storage to internal storage
await StorageAccessFramework.moveAsync({
from: permittedUri,
to: FileSystem.documentDirectory!,
});
const outputDir = FileSystem.documentDirectory! + albumName;
const migratedFiles = await FileSystem.readDirectoryAsync(outputDir);
// Creates assets from local files
const [newAlbumCreator, ...assets] = await Promise.all(
migratedFiles.map<Promise<MediaLibrary.Asset>>(
async fileName => await MediaLibrary.createAssetAsync(outputDir + '/' + fileName)
)
);
// Album was empty
if (!newAlbumCreator) {
return;
}
// Creates a new album in the scoped directory
const newAlbum = await MediaLibrary.createAlbumAsync(albumName, newAlbumCreator, false);
if (assets.length) {
await MediaLibrary.addAssetsToAlbumAsync(assets, newAlbum, false);
}
}