-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 画像ファイル対応 (LINE -> Slack ) * fix
- Loading branch information
Showing
5 changed files
with
97 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Net.Mime; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Net.Http.Headers; | ||
using SlackLineBridge.Services; | ||
|
||
namespace SlackLineBridge.Controllers | ||
{ | ||
[Route("[controller]")] | ||
[ApiController] | ||
public class ProxyController : ControllerBase | ||
{ | ||
IHttpClientFactory _clientFactory; | ||
string _lineChannelSecret; | ||
public ProxyController(IHttpClientFactory clientFactory, string lineChannelSecret) | ||
{ | ||
_clientFactory = clientFactory; | ||
_lineChannelSecret = lineChannelSecret; | ||
} | ||
|
||
[HttpGet("line/{token}/{id}")] | ||
public async Task<IActionResult> Line(string id, string token) | ||
{ | ||
if (token != LineMessageProcessingService.GetHMACHex(id, _lineChannelSecret)) | ||
{ | ||
return new StatusCodeResult((int)HttpStatusCode.Forbidden); | ||
} | ||
|
||
var client = _clientFactory.CreateClient("Line"); | ||
|
||
var result = await client.GetAsync($"https://api-data.line.me/v2/bot/message/{id}/content"); | ||
if (result.IsSuccessStatusCode) | ||
{ | ||
var stream = await result.Content.ReadAsStreamAsync(); | ||
var contentType = result.Content.Headers.GetValues("Content-Type").First(); | ||
|
||
return new FileStreamResult(stream, contentType); | ||
} | ||
else | ||
{ | ||
return new StatusCodeResult((int)result.StatusCode); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters