diff --git a/app/api/mobile/apis/memos.rb b/app/api/mobile/apis/memos.rb index c8c0041a..14654d10 100644 --- a/app/api/mobile/apis/memos.rb +++ b/app/api/mobile/apis/memos.rb @@ -29,6 +29,15 @@ module Mobile requires :id, type: Integer, desc: "帖子ID" end get ':id' do + # 记录用户流量源 + if params[:edu] + Rails.logger.info("####11111222##{@env['HTTP_X_REAL_IP']}") + ip = @env['HTTP_X_REAL_IP'] + ua = UserAgent.find_by_ip(ip) + unless ua + UserAgent.create(:key => params[:edu].strip, :ip => ip) + end + end MemosService.new.show params, current_user end diff --git a/app/models/user_agent.rb b/app/models/user_agent.rb new file mode 100644 index 00000000..b71c8449 --- /dev/null +++ b/app/models/user_agent.rb @@ -0,0 +1,3 @@ +class UserAgent < ActiveRecord::Base + +end diff --git a/db/migrate/20190716073605_create_user_agents.rb b/db/migrate/20190716073605_create_user_agents.rb new file mode 100644 index 00000000..22bc181e --- /dev/null +++ b/db/migrate/20190716073605_create_user_agents.rb @@ -0,0 +1,12 @@ +class CreateUserAgents < ActiveRecord::Migration + def change + create_table :user_agents do |t| + t.string :type + t.string :key + t.string :ip + + t.timestamps + end + add_index(:user_agents, :ip, :unique => true) + end +end diff --git a/public/react/src/modules/forums/MemoDetail.js b/public/react/src/modules/forums/MemoDetail.js index 075b2cd9..264f9be8 100644 --- a/public/react/src/modules/forums/MemoDetail.js +++ b/public/react/src/modules/forums/MemoDetail.js @@ -53,7 +53,7 @@ class MemoDetail extends Component { const { match } = this.props - const memoUrl = `/api/v1/memos/${match.params.memoId}`; + const memoUrl = `/api/v1/memos/${match.params.memoId}${window.location.search}`; this.setState({ memoLoading: true }) diff --git a/spec/factories/user_agents.rb b/spec/factories/user_agents.rb new file mode 100644 index 00000000..c8afcb41 --- /dev/null +++ b/spec/factories/user_agents.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :user_agent do + type 1 + key "MyString" + ip "MyString" + end +end diff --git a/spec/models/user_agent_spec.rb b/spec/models/user_agent_spec.rb new file mode 100644 index 00000000..20fd5cf3 --- /dev/null +++ b/spec/models/user_agent_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe UserAgent, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end