Skip to content

Commit

Permalink
fix urls from http://localhost:8081/api/storage/public/:chatId, renam…
Browse files Browse the repository at this point in the history
…e publicUrl to publishedUrl
  • Loading branch information
nkonev committed Jan 16, 2025
1 parent 11fef45 commit 0d64de6
Show file tree
Hide file tree
Showing 19 changed files with 160 additions and 82 deletions.
15 changes: 6 additions & 9 deletions chat/handlers/blog.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (h *BlogHandler) getPostsWoUsers(ctx context.Context, blogs []*db.Blog) ([]
query.Set(utils.FileParam, utils.SetImagePreviewExtension(fileParam))
dumbUrl.RawQuery = query.Encode()

publicPreviewUrl, err := makeUrlPublic(dumbUrl.String(), utils.UrlStorageEmbedPreview, false, post.ChatId, post.MessageId)
publicPreviewUrl, err := makeUrlPublic(dumbUrl.String(), utils.UrlStorageEmbedPreview, post.ChatId, post.MessageId)
if err != nil {
h.lgr.WithTracing(ctx).Warnf("Unagle to change url: %v", err)
break
Expand Down Expand Up @@ -503,7 +503,7 @@ func PatchStorageUrlToPublic(ctx context.Context, lgr *logger.Logger, text strin
original, originalExists := maybeImage.Attr("data-original")
if originalExists { // we have 2 tags - preview (small, tag attr) and original (data-original attr)
if utils.ContainsUrl(lgr, wlArr, original) { // original
newurl, err := makeUrlPublic(original, "", false, overrideChatId, overrideMessageId)
newurl, err := makeUrlPublic(original, "", overrideChatId, overrideMessageId)
if err != nil {
lgr.WithTracing(ctx).Warnf("Unagle to change url: %v", err)
return
Expand All @@ -513,7 +513,7 @@ func PatchStorageUrlToPublic(ctx context.Context, lgr *logger.Logger, text strin

src, srcExists := maybeImage.Attr("src") // preview
if srcExists && utils.ContainsUrl(lgr, wlArr, src) {
newurl, err := makeUrlPublic(src, utils.UrlStorageEmbedPreview, false, overrideChatId, overrideMessageId)
newurl, err := makeUrlPublic(src, utils.UrlStorageEmbedPreview, overrideChatId, overrideMessageId)
if err != nil {
lgr.WithTracing(ctx).Warnf("Unagle to change url: %v", err)
return
Expand Down Expand Up @@ -544,7 +544,8 @@ func (h *BlogHandler) getFileParam(src string) (string, error) {
const OverrideMessageId = "overrideMessageId"
const OverrideChatId = "overrideChatId"

func makeUrlPublic(src string, additionalSegment string, addTime bool, overrideChatId, overrideMessageId int64) (string, error) {
// see also storage/services/files.go :: makeUrlPublic
func makeUrlPublic(src string, additionalSegment string, overrideChatId, overrideMessageId int64) (string, error) {
if strings.HasPrefix(src, "/api/storage/assets/") { // don't touch built-in default urls (used for video-by-link, audio)
return src, nil
}
Expand All @@ -555,14 +556,10 @@ func makeUrlPublic(src string, additionalSegment string, addTime bool, overrideC
return "", err
}

parsed.Path = utils.UrlApiPrefix + utils.UrlStoragePublicGetFile + additionalSegment
parsed.Path = utils.UrlStoragePublicGetFile + additionalSegment

query := parsed.Query()

if addTime {
addTimeToUrlValues(&query)
}

query.Set(OverrideMessageId, utils.Int64ToString(overrideMessageId))
query.Set(OverrideChatId, utils.Int64ToString(overrideChatId))

Expand Down
3 changes: 1 addition & 2 deletions chat/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ func Min(a, b int) int {
}

const FileParam = "file"
const UrlApiPrefix = "/api"
const UrlStoragePublicGetFile = "/storage/public/download"
const UrlStoragePublicGetFile = "/api/storage/public/download"
const UrlStorageEmbedPreview = "/embed/preview"

func SetImagePreviewExtension(key string) string {
Expand Down
2 changes: 1 addition & 1 deletion event/dto/rabbitmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ type FileInfoDto struct {
Id string `json:"id"`
Filename string `json:"filename"`
Url string `json:"url"`
PublicUrl *string `json:"publicUrl"`
PublishedUrl *string `json:"publishedUrl"`
PreviewUrl *string `json:"previewUrl"`
Size int64 `json:"size"`
CanDelete bool `json:"canDelete"`
Expand Down
24 changes: 12 additions & 12 deletions event/graph/generated.go

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

2 changes: 1 addition & 1 deletion event/graph/model/models_gen.go

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

2 changes: 1 addition & 1 deletion event/graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ type FileInfoDto {
id: String!
filename: String!
url: String!
publicUrl: String
publishedUrl: String
previewUrl: String
size: Int64!
canDelete: Boolean!
Expand Down
2 changes: 1 addition & 1 deletion event/graph/schema.resolvers.go

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

2 changes: 1 addition & 1 deletion frontend/src/ChatView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ export default {
id
filename
url
publicUrl
publishedUrl
previewUrl
size
canDelete
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/FileListContextMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default {
}
if (this.menuableItem.canShare) {
if (!this.menuableItem.publicUrl) {
if (!this.menuableItem.publishedUrl) {
ret.push({
title: this.$vuetify.locale.t('$vuetify.share_file'),
icon: 'mdi-export',
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/FileListModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
{{ formattedSize(item.size) }}
<span v-if="item.owner"> {{ $vuetify.locale.t('$vuetify.files_by') }} {{item.owner?.login}}</span>
<span> {{$vuetify.locale.t('$vuetify.time_at')}} </span>{{getDate(item)}}
<a v-if="item.publicUrl" :href="item.publicUrl" target="_blank" class="colored-link">
<a v-if="item.publishedUrl" :href="item.publishedUrl" target="_blank" class="colored-link">
{{ $vuetify.locale.t('$vuetify.files_public_url') }}
</a>
</v-card-subtitle>
Expand All @@ -85,11 +85,11 @@
<v-btn size="medium" v-if="item.canEdit" @click="fireEdit(item)" :title="$vuetify.locale.t('$vuetify.edit')"><v-icon size="large">mdi-pencil</v-icon></v-btn>

<template v-if="item.canShare">
<v-btn size="medium" v-if="!item.publicUrl" @click="shareFile(item)">
<v-btn size="medium" v-if="!item.publishedUrl" @click="shareFile(item)">
<v-icon color="primary" size="large" dark :title="$vuetify.locale.t('$vuetify.share_file')">mdi-export</v-icon>
</v-btn>

<v-btn size="medium" v-if="item.publicUrl" @click="unshareFile(item)">
<v-btn size="medium" v-if="item.publishedUrl" @click="unshareFile(item)">
<v-icon color="primary" size="large" dark :title="$vuetify.locale.t('$vuetify.unshare_file')">mdi-lock</v-icon>
</v-btn>
</template>
Expand Down Expand Up @@ -306,7 +306,7 @@ export default {
},
shareFile(dto) {
axios.put(`/api/storage/publish/file`, {id: dto.id, public: true}).then((resp)=>{
const link = resp.data.publicUrl;
const link = resp.data.publishedUrl;
if (link) {
navigator.clipboard.writeText(getUrlPrefix() + link);
this.setTempNotification(this.$vuetify.locale.t('$vuetify.published_file_link_copied'));
Expand Down
20 changes: 11 additions & 9 deletions public/common/components/FileListModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@
{{ formattedSize(item.size) }}
<span v-if="item.owner"> by {{item.owner?.login}}</span>
<span> at </span>{{getDate(item)}}
<a v-if="item.publicUrl" :href="item.publicUrl" target="_blank" class="colored-link">
Public url
</a>
</v-card-subtitle>
</v-container>
</v-img>
Expand Down Expand Up @@ -174,7 +171,8 @@ export default {
searchString: null,
showSearchButton: true,
markInstance: null,
chatId: null,
chatId: null, // overrideChatId
messageId: null, // overrideMessageId
fileUploadingSessionType: null,
correlationId: null,
fileListMode: false,
Expand Down Expand Up @@ -283,14 +281,15 @@ export default {
setStoredFileListMode(newValue);
},
hasLength,
isCachedRelevantToArguments({fileItemUuid, chatId}) {
return this.fileItemUuid == fileItemUuid && this.chatId == chatId
isCachedRelevantToArguments({fileItemUuid, chatId, messageId}) {
return this.fileItemUuid == fileItemUuid && this.chatId == chatId && this.messageId == messageId
},
initializeWithArguments({fileItemUuid, messageEditing, messageIdToDetachFiles, chatId, fileUploadingSessionType, correlationId}) {
initializeWithArguments({fileItemUuid, messageEditing, messageIdToDetachFiles, chatId, messageId, fileUploadingSessionType, correlationId}) {
this.messageIdToDetachFiles = messageIdToDetachFiles;
this.isMessageEditing = messageEditing;
this.fileItemUuid = fileItemUuid;
this.chatId = chatId;
this.messageId = messageId;
// just pass them to FileUploadModal
this.fileUploadingSessionType = fileUploadingSessionType;
Expand All @@ -300,12 +299,14 @@ export default {
// blog post: blogDto.messageId
// public message: messageDto.messageItem.id
// TODO curl -Ss --url 'http://localhost:1236/api/storage/public/1019?overrideChatId=1019&overrideMessageId=1' | jq
return axios.get(`/api/storage/${this.chatId}`, {
return axios.get(`/api/storage/public/${this.chatId}`, {
params: {
page: this.translatePage(),
size: PAGE_SIZE_SMALL,
fileItemUuid : this.fileItemUuid ? this.fileItemUuid : '',
searchString: this.searchString
searchString: this.searchString,
overrideChatId: this.chatId,
overrideMessageId: this.messageId,
},
})
},
Expand Down Expand Up @@ -379,6 +380,7 @@ export default {
},
clearOnReset() {
this.chatId = null;
this.messageId = null;
this.fileItemUuid = null;
this.searchString = null;
},
Expand Down
6 changes: 5 additions & 1 deletion public/pages/blog/post/@id/BlogPost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ export default {
onClickTrap(e)
},
onFilesClicked(item) {
const obj = {chatId: this.pageContext.data.blogDto.chatId, fileItemUuid : item.fileItemUuid};
const obj = {
chatId: this.pageContext.data.blogDto.chatId,
messageId: item.id,
fileItemUuid : item.fileItemUuid
};
bus.emit(OPEN_VIEW_FILES_DIALOG, obj);
},
},
Expand Down
6 changes: 3 additions & 3 deletions storage/config/config-dev/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ minio:
secured: false
internalEndpoint: 127.0.0.1:39000
interContainerUrl: http://minio:9000
publicUrlPrefix: /api/s3
publicDownloadTtl: 24h
publicUploadTtl: 24h
externalS3UrlPrefix: /api/s3
presignDownloadTtl: 24h
presignUploadTtl: 24h
accessKeyId: AKIAIOSFODNN7EXAMPLE
secretAccessKey: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
location: "europe-east"
Expand Down
6 changes: 3 additions & 3 deletions storage/dto/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type FileInfoDto struct {
Id string `json:"id"`
Filename string `json:"filename"`
Url string `json:"url"`
PublicUrl *string `json:"publicUrl"`
PublishedUrl *string `json:"publishedUrl"`
PreviewUrl *string `json:"previewUrl"`
Size int64 `json:"size"`
CanDelete bool `json:"canDelete"`
Expand All @@ -20,8 +20,8 @@ type FileInfoDto struct {
CanPlayAsVideo bool `json:"canPlayAsVideo"`
CanShowAsImage bool `json:"canShowAsImage"`
CanPlayAsAudio bool `json:"canPlayAsAudio"`
FileItemUuid string `json:"fileItemUuid"`
CorrelationId *string `json:"correlationId"`
FileItemUuid string `json:"fileItemUuid"`
CorrelationId *string `json:"correlationId"`
}

type WrappedFileInfoDto struct {
Expand Down
Loading

0 comments on commit 0d64de6

Please sign in to comment.