This commit is contained in:
@@ -21,6 +21,7 @@ class WikiAssetsController < ApplicationController
|
|||||||
file = params[:file]
|
file = params[:file]
|
||||||
return head :bad_request if file.blank?
|
return head :bad_request if file.blank?
|
||||||
|
|
||||||
|
asset = nil
|
||||||
page.with_lock do
|
page.with_lock do
|
||||||
no = page.next_asset_no
|
no = page.next_asset_no
|
||||||
alt_text = params[:alt_text].presence
|
alt_text = params[:alt_text].presence
|
||||||
@@ -33,6 +34,6 @@ class WikiAssetsController < ApplicationController
|
|||||||
page.update!(next_asset_no: no + 1)
|
page.update!(next_asset_no: no + 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: asset.as_json(methods: [:url])
|
render json: asset.as_json(only: [:wiki_page_id, :no], methods: [:url])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
class WikiAsset < ApplicationRecord
|
class WikiAsset < ApplicationRecord
|
||||||
self.primary_key = :wiki_page_id, :no
|
|
||||||
|
|
||||||
belongs_to :wiki_page
|
belongs_to :wiki_page
|
||||||
belongs_to :created_by_user, class_name: 'User'
|
belongs_to :created_by_user, class_name: 'User'
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class CreateWikiAssets < ActiveRecord::Migration[8.0]
|
class CreateWikiAssets < ActiveRecord::Migration[8.0]
|
||||||
def change
|
def change
|
||||||
create_table :wiki_assets, primary_key: [:wiki_page_id, :no] do |t|
|
create_table :wiki_assets do |t|
|
||||||
t.references :wiki_page, null: false, foreign_key: true, index: false
|
t.references :wiki_page, null: false, foreign_key: true, index: false
|
||||||
t.integer :no, null: false
|
t.integer :no, null: false
|
||||||
t.string :alt_text
|
t.string :alt_text
|
||||||
@@ -10,6 +10,7 @@ class CreateWikiAssets < ActiveRecord::Migration[8.0]
|
|||||||
end
|
end
|
||||||
|
|
||||||
add_index :wiki_assets, [:wiki_page_id, :sha256], unique: true
|
add_index :wiki_assets, [:wiki_page_id, :sha256], unique: true
|
||||||
|
add_index :wiki_assets, [:wiki_page_id, :no], unique: true
|
||||||
|
|
||||||
add_column :wiki_pages, :next_asset_no, :integer, null: false, default: 1
|
add_column :wiki_pages, :next_asset_no, :integer, null: false, default: 1
|
||||||
end
|
end
|
||||||
|
|||||||
Generated
+2
-1
@@ -239,7 +239,7 @@ ActiveRecord::Schema[8.0].define(version: 2026_03_23_192300) do
|
|||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "wiki_assets", primary_key: ["wiki_page_id", "no"], charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
create_table "wiki_assets", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
||||||
t.bigint "wiki_page_id", null: false
|
t.bigint "wiki_page_id", null: false
|
||||||
t.integer "no", null: false
|
t.integer "no", null: false
|
||||||
t.string "alt_text"
|
t.string "alt_text"
|
||||||
@@ -248,6 +248,7 @@ ActiveRecord::Schema[8.0].define(version: 2026_03_23_192300) do
|
|||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.index ["created_by_user_id"], name: "index_wiki_assets_on_created_by_user_id"
|
t.index ["created_by_user_id"], name: "index_wiki_assets_on_created_by_user_id"
|
||||||
|
t.index ["wiki_page_id", "no"], name: "index_wiki_assets_on_wiki_page_id_and_no", unique: true
|
||||||
t.index ["wiki_page_id", "sha256"], name: "index_wiki_assets_on_wiki_page_id_and_sha256", unique: true
|
t.index ["wiki_page_id", "sha256"], name: "index_wiki_assets_on_wiki_page_id_and_sha256", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export default (({ title: initTitle, body: initBody, onSubmit, id }: Props) => {
|
|||||||
formData,
|
formData,
|
||||||
{ headers: { 'Content-Type': 'multipart/form-data' } })
|
{ headers: { 'Content-Type': 'multipart/form-data' } })
|
||||||
|
|
||||||
return `{{img:${ asset.no }}}`
|
return asset.url
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const makeComponents = (preview = false) => (
|
|||||||
img: (({ src, alt }) => (
|
img: (({ src, alt }) => (
|
||||||
<img src={src ?? ''}
|
<img src={src ?? ''}
|
||||||
alt={alt ?? ''}
|
alt={alt ?? ''}
|
||||||
className="max-w-full h-auto rounded"/>)),
|
className="max-w-[240px] max-h-[320px]"/>)),
|
||||||
} as const satisfies Components)
|
} as const satisfies Components)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user