2018-10-31 08:35:02 -05:00
|
|
|
import { IDriveFile } from '../models/drive-file';
|
|
|
|
import config from '../config';
|
|
|
|
|
|
|
|
export default function(file: IDriveFile, thumbnail = false): string {
|
|
|
|
if (file == null) return null;
|
|
|
|
|
|
|
|
if (file.metadata.withoutChunks) {
|
|
|
|
if (thumbnail) {
|
2018-11-25 13:25:48 -06:00
|
|
|
return file.metadata.thumbnailUrl || file.metadata.webpublicUrl || file.metadata.url;
|
2018-10-31 08:35:02 -05:00
|
|
|
} else {
|
2018-11-25 13:25:48 -06:00
|
|
|
return file.metadata.webpublicUrl || file.metadata.url;
|
2018-10-31 08:35:02 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (thumbnail) {
|
|
|
|
return `${config.drive_url}/${file._id}?thumbnail`;
|
|
|
|
} else {
|
2018-11-25 13:25:48 -06:00
|
|
|
return `${config.drive_url}/${file._id}?web`;
|
2018-10-31 08:35:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-25 13:25:48 -06:00
|
|
|
|
|
|
|
export function getOriginalUrl(file: IDriveFile) {
|
|
|
|
if (file.metadata && file.metadata.url) {
|
|
|
|
return file.metadata.url;
|
|
|
|
}
|
|
|
|
|
|
|
|
const accessKey = file.metadata ? file.metadata.accessKey : null;
|
|
|
|
return `${config.drive_url}/${file._id}${accessKey ? '?original=' + accessKey : ''}`;
|
|
|
|
}
|