chore(web): generate API functions with a single argument (#2568)

This commit is contained in:
Sergey Kondrikov 2023-05-28 04:52:22 +03:00 committed by GitHub
parent a460940430
commit 6c6c5ef651
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
65 changed files with 1913 additions and 491 deletions

View file

@ -10,7 +10,7 @@
const deleteUser = async () => {
try {
const deletedUser = await api.userApi.deleteUser(user.id);
const deletedUser = await api.userApi.deleteUser({ userId: user.id });
if (deletedUser.data.deletedAt != null) {
dispatch('user-delete-success');
} else {

View file

@ -102,7 +102,7 @@
const title = jobDetails[jobId]?.title;
try {
const { data } = await api.jobApi.sendJobCommand(jobId, jobCommand);
const { data } = await api.jobApi.sendJobCommand({ jobId, jobCommandDto: jobCommand });
jobs[jobId] = data;
switch (jobCommand.command) {

View file

@ -8,7 +8,7 @@
const dispatch = createEventDispatcher();
const restoreUser = async () => {
const restoredUser = await api.userApi.restoreUser(user.id);
const restoredUser = await api.userApi.restoreUser({ userId: user.id });
if (restoredUser.data.deletedAt == null) dispatch('user-restore-success');
else dispatch('user-restore-fail');
};

View file

@ -28,8 +28,10 @@
const { data: configs } = await api.systemConfigApi.getConfig();
const result = await api.systemConfigApi.updateConfig({
...configs,
ffmpeg: ffmpegConfig
systemConfigDto: {
...configs,
ffmpeg: ffmpegConfig
}
});
ffmpegConfig = { ...result.data.ffmpeg };

View file

@ -73,8 +73,10 @@
}
const { data: updated } = await api.systemConfigApi.updateConfig({
...current,
oauth: oauthConfig
systemConfigDto: {
...current,
oauth: oauthConfig
}
});
oauthConfig = { ...updated.oauth };

View file

@ -48,8 +48,10 @@
}
const { data: updated } = await api.systemConfigApi.updateConfig({
...current,
passwordLogin: passwordLoginConfig
systemConfigDto: {
...current,
passwordLogin: passwordLoginConfig
}
});
passwordLoginConfig = { ...updated.passwordLogin };

View file

@ -97,8 +97,10 @@
const { data: currentConfig } = await api.systemConfigApi.getConfig();
const result = await api.systemConfigApi.updateConfig({
...currentConfig,
storageTemplate: storageConfig
systemConfigDto: {
...currentConfig,
storageTemplate: storageConfig
}
});
storageConfig.template = result.data.storageTemplate.template;

View file

@ -86,9 +86,10 @@ describe('AlbumCard component', () => {
expect(albumImgElement).toHaveAttribute('alt', album.id);
expect(apiMock.assetApi.getAssetThumbnail).toHaveBeenCalledTimes(1);
expect(apiMock.assetApi.getAssetThumbnail).toHaveBeenCalledWith(
'thumbnailIdOne',
ThumbnailFormat.Jpeg,
undefined,
{
assetId: 'thumbnailIdOne',
format: ThumbnailFormat.Jpeg
},
{ responseType: 'blob' }
);
expect(createObjectURLMock).toHaveBeenCalledWith(thumbnailBlob);

View file

@ -36,9 +36,10 @@
}
const { data } = await api.assetApi.getAssetThumbnail(
thubmnailId,
ThumbnailFormat.Jpeg,
undefined,
{
assetId: thubmnailId,
format: ThumbnailFormat.Jpeg
},
{
responseType: 'blob'
}
@ -61,7 +62,7 @@
});
const getAlbumOwnerInfo = async (): Promise<UserResponseDto> => {
const { data } = await api.userApi.getUserById(album.ownerId);
const { data } = await api.userApi.getUserById({ userId: album.ownerId });
return data;
};

View file

@ -124,8 +124,11 @@
$: {
if (!isEditingTitle && currentAlbumName != album.albumName && isOwned) {
api.albumApi
.updateAlbumInfo(album.id, {
albumName: album.albumName
.updateAlbumInfo({
id: album.id,
updateAlbumDto: {
albumName: album.albumName
}
})
.then(() => {
currentAlbumName = album.albumName;
@ -143,13 +146,13 @@
const createAlbumHandler = async (event: CustomEvent) => {
const { assets }: { assets: AssetResponseDto[] } = event.detail;
try {
const { data } = await api.albumApi.addAssetsToAlbum(
album.id,
{
const { data } = await api.albumApi.addAssetsToAlbum({
id: album.id,
addAssetsDto: {
assetIds: assets.map((a) => a.id)
},
sharedLink?.key
);
key: sharedLink?.key
});
if (data.album) {
album = data.album;
@ -168,8 +171,11 @@
const { selectedUsers }: { selectedUsers: UserResponseDto[] } = event.detail;
try {
const { data } = await api.albumApi.addUsersToAlbum(album.id, {
sharedUserIds: Array.from(selectedUsers).map((u) => u.id)
const { data } = await api.albumApi.addUsersToAlbum({
id: album.id,
addUsersDto: {
sharedUserIds: Array.from(selectedUsers).map((u) => u.id)
}
});
album = data;
@ -193,7 +199,7 @@
}
try {
const { data } = await api.albumApi.getAlbumInfo(album.id);
const { data } = await api.albumApi.getAlbumInfo({ id: album.id });
album = data;
isShowShareInfoModal = false;
@ -213,7 +219,7 @@
)
) {
try {
await api.albumApi.deleteAlbum(album.id);
await api.albumApi.deleteAlbum({ id: album.id });
goto(backUrl);
} catch (e) {
console.error('Error [userDeleteMenu] ', e);
@ -241,10 +247,7 @@
let total = 0;
const { data, status, headers } = await api.albumApi.downloadArchive(
album.id,
undefined,
skip || undefined,
sharedLink?.key,
{ id: album.id, skip: skip || undefined, key: sharedLink?.key },
{
responseType: 'blob',
onDownloadProgress: function (progressEvent) {
@ -311,8 +314,11 @@
const setAlbumThumbnailHandler = (event: CustomEvent) => {
const { asset }: { asset: AssetResponseDto } = event.detail;
try {
api.albumApi.updateAlbumInfo(album.id, {
albumThumbnailAssetId: asset.id
api.albumApi.updateAlbumInfo({
id: album.id,
updateAlbumDto: {
albumThumbnailAssetId: asset.id
}
});
} catch (e) {
console.error('Error [setAlbumThumbnailHandler] ', e);

View file

@ -53,7 +53,7 @@
const removeUser = async (userId: string) => {
if (window.confirm('Do you want to remove selected user from the album?')) {
try {
await api.albumApi.removeUserFromAlbum(album.id, userId);
await api.albumApi.removeUserFromAlbum({ id: album.id, userId });
dispatch('user-deleted', { userId });
} catch (e) {
console.error('Error [share-info-modal] [removeUser]', e);

View file

@ -19,7 +19,7 @@
let sharedLinks: SharedLinkResponseDto[] = [];
onMount(async () => {
await getSharedLinks();
const { data } = await api.userApi.getAllUsers(false);
const { data } = await api.userApi.getAllUsers({ isAll: false });
// remove invalid users
users = data.filter((user) => !(user.deletedAt || user.id === album.ownerId));

View file

@ -65,7 +65,7 @@
const getAllAlbums = async () => {
try {
const { data } = await api.albumApi.getAllAlbums(undefined, asset.id);
const { data } = await api.albumApi.getAllAlbums({ assetId: asset.id });
appearsInAlbums = data;
} catch (e) {
console.error('Error getting album that asset belong to', e);
@ -151,16 +151,19 @@
$downloadAssets[imageFileName] = 0;
const { data, status } = await api.assetApi.downloadFile(assetId, key, {
responseType: 'blob',
onDownloadProgress: (progressEvent) => {
if (progressEvent.lengthComputable) {
const total = progressEvent.total;
const current = progressEvent.loaded;
$downloadAssets[imageFileName] = Math.floor((current / total) * 100);
const { data, status } = await api.assetApi.downloadFile(
{ assetId, key },
{
responseType: 'blob',
onDownloadProgress: (progressEvent) => {
if (progressEvent.lengthComputable) {
const total = progressEvent.total;
const current = progressEvent.loaded;
$downloadAssets[imageFileName] = Math.floor((current / total) * 100);
}
}
}
});
);
if (!(data instanceof Blob)) {
return;
@ -203,7 +206,9 @@
)
) {
const { data: deletedAssets } = await api.assetApi.deleteAsset({
ids: [asset.id]
deleteAssetDto: {
ids: [asset.id]
}
});
navigateAssetForward();
@ -224,8 +229,11 @@
};
const toggleFavorite = async () => {
const { data } = await api.assetApi.updateAsset(asset.id, {
isFavorite: !asset.isFavorite
const { data } = await api.assetApi.updateAsset({
assetId: asset.id,
updateAssetDto: {
isFavorite: !asset.isFavorite
}
});
asset.isFavorite = data.isFavorite;
@ -241,10 +249,12 @@
isShowAlbumPicker = false;
const { albumName }: { albumName: string } = event.detail;
api.albumApi.createAlbum({ albumName, assetIds: [asset.id] }).then((response) => {
const album = response.data;
goto('/albums/' + album.id);
});
api.albumApi
.createAlbum({ createAlbumDto: { albumName, assetIds: [asset.id] } })
.then((response) => {
const album = response.data;
goto('/albums/' + album.id);
});
};
const handleAddToAlbum = async (event: CustomEvent<{ album: AlbumResponseDto }>) => {
@ -272,8 +282,11 @@
const toggleArchive = async () => {
try {
const { data } = await api.assetApi.updateAsset(asset.id, {
isArchived: !asset.isArchived
const { data } = await api.assetApi.updateAsset({
assetId: asset.id,
updateAssetDto: {
isArchived: !asset.isArchived
}
});
asset.isArchived = data.isArchived;

View file

@ -21,7 +21,7 @@
$: {
// Get latest description from server
if (asset.id) {
api.assetApi.getAssetById(asset.id).then((res) => {
api.assetApi.getAssetById({ assetId: asset.id }).then((res) => {
people = res.data?.people || [];
textarea.value = res.data?.exifInfo?.description || '';
});
@ -64,8 +64,11 @@
const handleFocusOut = async () => {
dispatch('description-focus-out');
try {
await api.assetApi.updateAsset(asset.id, {
description: description
await api.assetApi.updateAsset({
assetId: asset.id,
updateAssetDto: {
description: description
}
});
} catch (error) {
console.error(error);

View file

@ -26,9 +26,12 @@
const loadAssetData = async () => {
try {
const { data } = await api.assetApi.serveFile(asset.id, false, true, publicSharedKey, {
responseType: 'blob'
});
const { data } = await api.assetApi.serveFile(
{ assetId: asset.id, isThumb: false, isWeb: true, key: publicSharedKey },
{
responseType: 'blob'
}
);
if (!(data instanceof Blob)) {
return;

View file

@ -31,10 +31,12 @@
const lastName = form.get('lastName');
const { status } = await api.authenticationApi.adminSignUp({
email: String(email),
password: String(password),
firstName: String(firstName),
lastName: String(lastName)
signUpDto: {
email: String(email),
password: String(password),
firstName: String(firstName),
lastName: String(lastName)
}
});
if (status === 201) {

View file

@ -29,9 +29,11 @@
error = '';
const { status } = await api.userApi.updateUser({
id: user.id,
password: String(password),
shouldChangePassword: false
updateUserDto: {
id: user.id,
password: String(password),
shouldChangePassword: false
}
});
if (status === 200) {

View file

@ -46,10 +46,12 @@
try {
const { status } = await api.userApi.createUser({
email: String(email),
password: String(password),
firstName: String(firstName),
lastName: String(lastName)
createUserDto: {
email: String(email),
password: String(password),
firstName: String(firstName),
lastName: String(lastName)
}
});
if (status === 201) {

View file

@ -21,11 +21,13 @@
try {
const { id, email, firstName, lastName, storageLabel } = user;
const { status } = await api.userApi.updateUser({
id,
email,
firstName,
lastName,
storageLabel: storageLabel || ''
updateUserDto: {
id,
email,
firstName,
lastName,
storageLabel: storageLabel || ''
}
});
if (status === 200) {
@ -42,9 +44,11 @@
const defaultPassword = 'password';
const { status } = await api.userApi.updateUser({
id: user.id,
password: defaultPassword,
shouldChangePassword: true
updateUserDto: {
id: user.id,
password: defaultPassword,
shouldChangePassword: true
}
});
if (status == 200) {

View file

@ -57,8 +57,10 @@
loading = true;
const { data } = await api.authenticationApi.login({
email,
password
loginCredentialDto: {
email,
password
}
});
if (!data.isAdmin && data.shouldChangePassword) {

View file

@ -27,7 +27,7 @@
const { albumName }: { albumName: string } = event.detail;
const assetIds = Array.from(getAssets()).map((asset) => asset.id);
api.albumApi.createAlbum({ albumName, assetIds }).then((response) => {
api.albumApi.createAlbum({ createAlbumDto: { albumName, assetIds } }).then((response) => {
const { id, albumName } = response.data;
notificationController.show({

View file

@ -28,7 +28,7 @@
for (const asset of getAssets()) {
if (asset.isArchived !== isArchived) {
api.assetApi.updateAsset(asset.id, { isArchived });
api.assetApi.updateAsset({ assetId: asset.id, updateAssetDto: { isArchived } });
onAssetArchive(asset, isArchived);
cnt = cnt + 1;

View file

@ -20,7 +20,9 @@
let count = 0;
const { data: deletedAssets } = await api.assetApi.deleteAsset({
ids: Array.from(getAssets()).map((a) => a.id)
deleteAssetDto: {
ids: Array.from(getAssets()).map((a) => a.id)
}
});
for (const asset of deletedAssets) {

View file

@ -28,7 +28,7 @@
let cnt = 0;
for (const asset of getAssets()) {
if (asset.isFavorite !== isFavorite) {
api.assetApi.updateAsset(asset.id, { isFavorite });
api.assetApi.updateAsset({ assetId: asset.id, updateAssetDto: { isFavorite } });
onAssetFavorite(asset, isFavorite);
cnt = cnt + 1;
}

View file

@ -15,8 +15,11 @@
const handleRemoveFromAlbum = async () => {
if (window.confirm('Do you want to remove selected assets from the album?')) {
try {
const { data } = await api.albumApi.removeAssetFromAlbum(album.id, {
assetIds: Array.from(getAssets()).map((a) => a.id)
const { data } = await api.albumApi.removeAssetFromAlbum({
id: album.id,
removeAssetsDto: {
assetIds: Array.from(getAssets()).map((a) => a.id)
}
});
album = data;

View file

@ -14,12 +14,12 @@
// TODO: Rename API method or change functionality. The assetIds passed
// in are kept instead of removed.
const assetsToKeep = allAssets.filter((a) => !getAssets().has(a));
await api.assetApi.removeAssetsFromSharedLink(
{
await api.assetApi.removeAssetsFromSharedLink({
removeAssetsDto: {
assetIds: assetsToKeep.map((a) => a.id)
},
sharedLink?.key
);
key: sharedLink?.key
});
sharedLink.assets = assetsToKeep;
clearSelect();

View file

@ -28,8 +28,10 @@
onMount(async () => {
const { data: assetCountByTimebucket } = await api.assetApi.getAssetCountByTimeBucket({
timeGroup: TimeGroupEnum.Month,
userId: user?.id
getAssetCountByTimeBucketDto: {
timeGroup: TimeGroupEnum.Month,
userId: user?.id
}
});
bucketInfo = assetCountByTimebucket;

View file

@ -40,12 +40,12 @@
const assetIds = results.filter((id) => !!id) as string[];
await api.assetApi.addAssetsToSharedLink(
{
await api.assetApi.addAssetsToSharedLink({
addAssetsDto: {
assetIds
},
sharedLink?.key
);
key: sharedLink?.key
});
notificationController.show({
message: `Successfully add ${assetIds.length} to the shared link`,

View file

@ -16,7 +16,7 @@
export let shared: boolean;
onMount(async () => {
const { data } = await api.albumApi.getAllAlbums(shared || undefined);
const { data } = await api.albumApi.getAllAlbums({ shared: shared || undefined });
albums = data;
recentAlbums = albums

View file

@ -10,9 +10,12 @@
const dispatch = createEventDispatcher();
const getUserAvatar = async () => {
const { data } = await api.userApi.getProfileImage(user.id, {
responseType: 'blob'
});
const { data } = await api.userApi.getProfileImage(
{ userId: user.id },
{
responseType: 'blob'
}
);
if (data instanceof Blob) {
return URL.createObjectURL(data);

View file

@ -60,22 +60,26 @@
try {
if (shareType === SharedLinkType.Album && album) {
const { data } = await api.albumApi.createAlbumSharedLink({
albumId: album.id,
expiresAt: expirationDate,
allowUpload: isAllowUpload,
description: description,
allowDownload: isAllowDownload,
showExif: shouldShowExif
createAlbumShareLinkDto: {
albumId: album.id,
expiresAt: expirationDate,
allowUpload: isAllowUpload,
description: description,
allowDownload: isAllowDownload,
showExif: shouldShowExif
}
});
buildSharedLink(data);
} else {
const { data } = await api.assetApi.createAssetsSharedLink({
assetIds: sharedAssets.map((a) => a.id),
expiresAt: expirationDate,
allowUpload: isAllowUpload,
description: description,
allowDownload: isAllowDownload,
showExif: shouldShowExif
createAssetsShareLinkDto: {
assetIds: sharedAssets.map((a) => a.id),
expiresAt: expirationDate,
allowUpload: isAllowUpload,
description: description,
allowDownload: isAllowDownload,
showExif: shouldShowExif
}
});
buildSharedLink(data);
}
@ -133,12 +137,15 @@
? new Date(currentTime + expirationTime).toISOString()
: null;
await api.shareApi.editSharedLink(editingLink.id, {
description,
expiresAt: shouldChangeExpirationTime ? expirationDate : undefined,
allowUpload: isAllowUpload,
allowDownload: isAllowDownload,
showExif: shouldShowExif
await api.shareApi.editSharedLink({
id: editingLink.id,
editSharedLinkDto: {
description,
expiresAt: shouldChangeExpirationTime ? expirationDate : undefined,
allowUpload: isAllowUpload,
allowDownload: isAllowDownload,
showExif: shouldShowExif
}
});
notificationController.show({

View file

@ -30,7 +30,7 @@
const getFavoriteCount = async () => {
try {
const { data: assets } = await api.assetApi.getAllAssets(undefined, true, undefined);
const { data: assets } = await api.assetApi.getAllAssets({ isFavorite: true });
return {
favorites: assets.length

View file

@ -30,7 +30,7 @@
assetId = link.assets[0].id;
}
const { data } = await api.assetApi.getAssetById(assetId);
const { data } = await api.assetApi.getAssetById({ assetId });
return data;
};

View file

@ -17,8 +17,10 @@
const handleChangePassword = async () => {
try {
await api.authenticationApi.changePassword({
password,
newPassword
changePasswordDto: {
password,
newPassword
}
});
notificationController.show({

View file

@ -29,7 +29,7 @@
}
try {
await api.authenticationApi.logoutAuthDevice(deleteDevice.id);
await api.authenticationApi.logoutAuthDevice({ id: deleteDevice.id });
notificationController.show({ message: `Logged out device`, type: NotificationType.Info });
} catch (error) {
handleError(error, 'Unable to log out device');

View file

@ -15,13 +15,13 @@
onMount(async () => {
// TODO: update endpoint to have a query param for deleted users
let { data: users } = await api.userApi.getAllUsers(false);
let { data: users } = await api.userApi.getAllUsers({ isAll: false });
// remove invalid users
users = users.filter((_user) => !(_user.deletedAt || _user.id === user.id));
// exclude partners from the list of users available for selection
const { data: partners } = await api.partnerApi.getPartners('shared-by');
const { data: partners } = await api.partnerApi.getPartners({ direction: 'shared-by' });
const partnerIds = partners.map((partner) => partner.id);
availableUsers = users.filter((user) => !partnerIds.includes(user.id));
});

View file

@ -16,7 +16,7 @@
let removePartner: UserResponseDto | null = null;
const refreshPartners = async () => {
const { data } = await api.partnerApi.getPartners('shared-by');
const { data } = await api.partnerApi.getPartners({ direction: 'shared-by' });
partners = data;
};
@ -26,7 +26,7 @@
}
try {
await api.partnerApi.removePartner(removePartner.id);
await api.partnerApi.removePartner({ id: removePartner.id });
removePartner = null;
await refreshPartners();
} catch (error) {
@ -37,7 +37,7 @@
const handleCreatePartners = async (users: UserResponseDto[]) => {
try {
for (const user of users) {
await api.partnerApi.createPartner(user.id);
await api.partnerApi.createPartner({ id: user.id });
}
await refreshPartners();

View file

@ -40,7 +40,7 @@
const handleCreate = async (event: CustomEvent<APIKeyResponseDto>) => {
try {
const dto = event.detail;
const { data } = await api.keyApi.createKey(dto);
const { data } = await api.keyApi.createKey({ aPIKeyCreateDto: dto });
secret = data.secret;
} catch (error) {
handleError(error, 'Unable to create a new API Key');
@ -58,7 +58,7 @@
const dto = event.detail;
try {
await api.keyApi.updateKey(editKey.id, { name: dto.name });
await api.keyApi.updateKey({ id: editKey.id, aPIKeyUpdateDto: { name: dto.name } });
notificationController.show({
message: `Saved API Key`,
type: NotificationType.Info
@ -77,7 +77,7 @@
}
try {
await api.keyApi.deleteKey(deleteKey.id);
await api.keyApi.deleteKey({ id: deleteKey.id });
notificationController.show({
message: `Removed API Key: ${deleteKey.name}`,
type: NotificationType.Info

View file

@ -16,10 +16,12 @@
const handleSaveProfile = async () => {
try {
const { data } = await api.userApi.updateUser({
id: user.id,
email: user.email,
firstName: user.firstName,
lastName: user.lastName
updateUserDto: {
id: user.id,
email: user.email,
firstName: user.firstName,
lastName: user.lastName
}
});
Object.assign(user, data);