Skip to content

feat: Upload images from markdown files to CDN when publishing#16033

Merged
kodiakhq[bot] merged 29 commits into
mainfrom
feat/upload-markdown-images
Jan 11, 2024
Merged

feat: Upload images from markdown files to CDN when publishing#16033
kodiakhq[bot] merged 29 commits into
mainfrom
feat/upload-markdown-images

Conversation

@disq
Copy link
Copy Markdown
Member

@disq disq commented Jan 4, 2024

Limited testing results:

# Test Addon README
![Troll face](https://storage.googleapis.com/cq-cloud-images/kemal/6027b3c3f2afcb2cf2c9405637a40690adb9a675_troll.png "Trollface")
## Installation
![](https://storage.googleapis.com/cq-cloud-images/kemal/4b0b26dd0e5113344c3d655dce252c8778ffadd3_tldr.png)
![](https://storage.googleapis.com/cq-cloud-images/kemal/bf66c0a36876f9854f80883c609694a9ec653dac_1000.png)
## One more heading
![Troll face 2](https://storage.googleapis.com/cq-cloud-images/kemal/6027b3c3f2afcb2cf2c9405637a40690adb9a675_troll.png)

Newly supported:

  • HTML <img> tags in markdown (will try to fix this, but need to make sure it doesn't replace inside code blocks)
  • Reference-style image syntax (with ids, documented here)

@disq disq requested a review from yevgenypats as a code owner January 4, 2024 17:34
@disq disq requested a review from hermanschaaf January 4, 2024 17:34
@cq-bot cq-bot added the area/cli label Jan 4, 2024
Comment thread cli/go.mod Outdated
@disq disq requested a review from erezrokah January 4, 2024 19:04
Comment thread cli/internal/publish/images.go Outdated
Comment thread cli/internal/publish/images.go Outdated
Comment thread cli/internal/publish/images_test.go Outdated
Comment thread cli/internal/publish/images.go Outdated
Copy link
Copy Markdown
Contributor

@hermanschaaf hermanschaaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a first pass review; I think overall it looks good enough for a first version. Most of my comments are just suggestions for possible improvement, perhaps worth some comments in the code at least if we don't want to improve them now.

My two main comments are:

  • the one about the replace directive on github.com/cloudquery/cloudquery-api-go before merging
  • the one about the test cases seeming hard to write / validate, I think it would make sense to split the tests

@disq disq requested a review from candiduslynx January 5, 2024 21:20
}
p := goldmark.New(
goldmark.WithParserOptions(
parser.WithASTTransformers(util.Prioritized(imf, 999999)),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this priority matters, or if it should be lowest

Copy link
Copy Markdown
Contributor

@candiduslynx candiduslynx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just some suggestions

Comment thread cli/internal/publish/images.go Outdated
Comment thread cli/internal/publish/images.go Outdated
checksum, name := refParts[0], refParts[1]

reqs = append(reqs, cloudquery_api.TeamImageCreate{
Name: name,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be solved elsewhere, but we shouldn't overwrite files in storage (i.e., every new uploaded version should be treated as a separate file, rather than the same one).
Although it might be OK to just use name + checksum as a key, there might be collisions still, & the data overwrite can result in some odd artifacts in the old versions of the doc page.

We also should think about file size limits (it's funny how many people would use anything as free file storage given the opportunity).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct it's solved elsewhere (see the relevant PR in the backend repo) the backend will do a HEAD and if there is an object on the same 'calculated path' it won't return an upload url.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File size limits are also not a discussion for clients, we also have the ability to lock out each team from uploading.

Comment thread cli/internal/publish/images.go
Comment thread cli/internal/publish/images.go Outdated
Comment thread cli/internal/publish/images.go Outdated
Comment on lines +162 to +172
for _, p := range posList {
if p.end {
open--
} else {
open++
}
if open > 1 {
return nil, fmt.Errorf("found overlapping range: %d-%d", lastPos, p.at)
}
lastPos = p.at
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for _, p := range posList {
if p.end {
open--
} else {
open++
}
if open > 1 {
return nil, fmt.Errorf("found overlapping range: %d-%d", lastPos, p.at)
}
lastPos = p.at
}
for i, r := range posList[1:] {
l := posList[i]
if l.end >= r.start {
return nil, fmt.Errorf("found overlapping range: %d-%d", r.start, l.end)
}
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about positions starting at the same point? this start/end stuff leads to more complicated code for this use case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also see @hermanschaaf 's comment in #16033 (comment)

Comment thread cli/internal/publish/images.go
Comment thread cli/internal/publish/images.go Outdated
Comment thread cli/internal/publish/images.go Outdated
Comment thread cli/internal/publish/images.go Outdated
@disq disq added the automerge Automatically merge once required checks pass label Jan 11, 2024
@kodiakhq kodiakhq Bot merged commit cf7cdb1 into main Jan 11, 2024
@kodiakhq kodiakhq Bot deleted the feat/upload-markdown-images branch January 11, 2024 23:03
kodiakhq Bot pushed a commit that referenced this pull request Jan 12, 2024
🤖 I have created a release *beep* *boop*
---


## [5.0.0](cli-v4.4.0...cli-v5.0.0) (2024-01-12)


### ⚠ BREAKING CHANGES

* Remove deprecated top level spec options (#15999). The following deprecated spec options were removed:
    * source plugin top level spec:
      * `concurrency`
      * `table_concurrency`
      * `resource_concurrency`
      * `backend`
      * `backend_spec`
    * destination plugin top level spec:
      * `batch_size`
      * `batch_size_bytes`
      
    **For most users this shouldn't be a breaking change**. We've deprecated these options a while ago and some were moved to the plugin level spec. If you were using the deprecated options on a CLI version lower than `v5.0.0` you should have gotten a warning about it.

### Features

* Add JSON schema for CLI specs ([#15998](#15998)) ([da02049](da02049))
* Remove deprecated spec options (#15999) ([9e25f4a](9e25f4a))
* Upload images from markdown files to CDN when publishing ([#16033](#16033)) ([cf7cdb1](cf7cdb1))


### Bug Fixes

* Add `X-Meta-User-Team-Name` during docker push ([#16013](#16013)) ([129b7c2](129b7c2))
* Add missing `X-Meta-User-Team-Name` header and manifest types option ([#16113](#16113)) ([9d8899e](9d8899e))
* **deps:** Update github.com/apache/arrow/go/v15 digest to 6d44906 ([#16115](#16115)) ([8b0ae62](8b0ae62))
* **deps:** Update module github.com/cloudquery/cloudquery-api-go to v1.6.4 ([#16067](#16067)) ([2e7b7d6](2e7b7d6))
* **deps:** Update module github.com/cloudquery/plugin-pb-go to v1.16.2 ([#15948](#15948)) ([2def2ef](2def2ef))
* **deps:** Update module github.com/cloudquery/plugin-pb-go to v1.16.3 ([#16002](#16002)) ([e2d5605](e2d5605))
* **deps:** Update module github.com/cloudquery/plugin-pb-go to v1.16.4 ([#16126](#16126)) ([6a776ae](6a776ae))
* **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.25.0 ([#15932](#15932)) ([2292b5a](2292b5a))
* **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.25.1 ([#16069](#16069)) ([edda65c](edda65c))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cli automerge Automatically merge once required checks pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants